fixes #2731: Expunged posts should clear favorite groups
This commit is contained in:
@@ -18,6 +18,11 @@ class FavoriteGroup < ActiveRecord::Base
|
||||
where("favorite_groups.creator_id = ?", user_id)
|
||||
end
|
||||
|
||||
def for_post(post_id)
|
||||
regexp = "(^#{post_id}$|^#{post_id} | #{post_id}$| #{post_id} )"
|
||||
where("favorite_groups.post_ids ~ ?", regexp)
|
||||
end
|
||||
|
||||
def named(name)
|
||||
where("lower(name) = ?", name.to_s.mb_chars.downcase.strip)
|
||||
end
|
||||
|
||||
@@ -959,6 +959,12 @@ class Post < ActiveRecord::Base
|
||||
groups.uniq
|
||||
end
|
||||
end
|
||||
|
||||
def remove_from_fav_groups
|
||||
FavoriteGroup.for_post(id).find_each do |group|
|
||||
group.remove!(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module UploaderMethods
|
||||
@@ -1313,6 +1319,7 @@ class Post < ActiveRecord::Base
|
||||
update_children_on_destroy
|
||||
decrement_tag_post_counts
|
||||
remove_from_all_pools
|
||||
remove_from_fav_groups
|
||||
destroy
|
||||
update_parent_on_destroy
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user