# Association question

**URL:** <https://www.ruby-forum.com/t/association-question/133624>\
**Category:** Ferret\
**Created:** [April 2, 2008, 3:39am UTC](https://www.ruby-forum.com/t/association-question/133624 "2008-04-02T03:39:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![s0nspark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f475e1/32.png) [@s0nspark](https://www.ruby-forum.com/u/s0nspark)\
**Post date:** [April 2, 2008, 3:39am UTC](https://www.ruby-forum.com/t/association-question/133624/1 "2008-04-02T03:39:44Z")

</div>

Hi,

I have a photos model that has\_many comments. When the photo is saved,  
it builds the comments into a string that is indexed.

When the comments are saved, it needs to re-index the comments from the  
photo model. The way I do it is by calling self.photo.save on the  
after\_save method of the comments model.

This seems botchy, is there a better way?

class Photo \< ActiveRecord::Base

has\_many :comments

acts\_as\_ferret :fields =\> [:title, :photo\_comments], :remote =\> true

def photo\_comments  
comments.collect{|c| c.comment}.join(’ ')  
end  
end

class Comment \< ActiveRecord::Base  
belongs\_to :account, :counter\_cache =\> true  
belongs\_to :photo, :counter\_cache =\> true

validates\_presence\_of :comment

def after\_save  
self.photo.save  
end

end

Thanks,

Tim
