假设我有一个包含许多帖子的内容对象,其中Post对象的属性委托给Content。因此,当我编辑一个帖子并保存它时,它会更新相关的内容对象,而后者又会更新所有其他可能与之关联的帖子,我试图避免的是帖子的情况引发内容更新回调的内容也会在内容回调中更新。这可能吗?
class Content > ActiveRecord::Base
has_many :posts
after_save :update_posts
def update_posts
#I'd like to make sure the post that kicked off the save doesn't get reindexed here
self.posts.each{|x| x.update_search_index}
end
end
class Post > ActiveRecord::Base
belongs_to :Content
after_save :update_content, :update_search_index
def save_content
self.content.save #this kicks off an aftersave callback on content that winds up recalling update_search_index, I'm trying to avoid that
end
def update_search_index
#persist post to search index
end
end