* Fixed favorites deletion

* Fixed parenting when dealing with post deletion
This commit is contained in:
albert
2012-01-06 18:20:18 -05:00
parent 365e04bb40
commit 073ab8ee96
5 changed files with 57 additions and 33 deletions

View File

@@ -1,4 +1,9 @@
class Favorite < ActiveRecord::Base
belongs_to :post
scope :for_user, lambda {|user_id| where("user_id % 100 = #{user_id.to_i % 100} and user_id = #{user_id.to_i}")}
# this is necessary because there's no trigger for deleting favorites
def self.destroy_all(hash)
connection.execute("delete from favorites_#{hash[:user_id] % 100} where user_id = #{hash[:user_id]} and post_id = #{hash[:post_id]}")
end
end