假设我有一个包含许多帖子的内容对象,帖子对象的属性委托给内容。因此,当我编辑帖子并保存它时,它会更新关联的内容对象,进而更新可能与之相关的所有其他帖子,我试图避免的是帖子的情况触发内容更新回调的内容也会在内容回调中更新。那可能吗?
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