* 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

@@ -198,14 +198,14 @@ class User < ActiveRecord::Base
end
def add_favorite!(post)
return if Favorite.exists?(:user_id => id, :post_id => post.id)
return if Favorite.for_user(id).exists?(:user_id => id, :post_id => post.id)
Favorite.create(:user_id => id, :post_id => post.id)
increment!(:favorite_count)
post.add_favorite!(self)
end
def remove_favorite!(post)
return unless Favorite.exists?(:user_id => id, :post_id => post.id)
return unless Favorite.for_user(id).exists?(:user_id => id, :post_id => post.id)
Favorite.destroy_all(:user_id => id, :post_id => post.id)
decrement!(:favorite_count)
post.remove_favorite!(self)