Merge pull request #2961 from evazion/fix-move-favs-user-assoc
Fix exception when moving favorites
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
class Favorite < ActiveRecord::Base
|
class Favorite < ActiveRecord::Base
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
|
belongs_to :user
|
||||||
scope :for_user, lambda {|user_id| where("user_id % 100 = #{user_id.to_i % 100} and user_id = #{user_id.to_i}")}
|
scope :for_user, lambda {|user_id| where("user_id % 100 = #{user_id.to_i % 100} and user_id = #{user_id.to_i}")}
|
||||||
attr_accessible :user_id, :post_id
|
attr_accessible :user_id, :post_id
|
||||||
|
|
||||||
|
|||||||
@@ -1282,9 +1282,11 @@ class Post < ActiveRecord::Base
|
|||||||
def give_favorites_to_parent
|
def give_favorites_to_parent
|
||||||
return if parent.nil?
|
return if parent.nil?
|
||||||
|
|
||||||
favorites.each do |fav|
|
transaction do
|
||||||
remove_favorite!(fav.user)
|
favorites.each do |fav|
|
||||||
parent.add_favorite!(fav.user)
|
remove_favorite!(fav.user)
|
||||||
|
parent.add_favorite!(fav.user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user