Content に委譲された Post オブジェクトの属性を持つ、多数の投稿を持つ Content オブジェクトがあるとします。そのため、投稿を編集して保存すると、関連する 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