* Fixed favorites deletion
* Fixed parenting when dealing with post deletion
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user