I have a…
class Resort < ActiveRecord::Base
has_many :photos, :order => “position”
end
class Photo < ActiveRecord::Base
belongs_to :resort
end
What I have a problem with is that if I update a photo I really need the
updated_at attribute on the Resort to change as well, how do I do this?
Thanks
bb
bingo bob wrote:
I have a…
class Resort < ActiveRecord::Base
has_many :photos, :order => “position”
end
class Photo < ActiveRecord::Base
belongs_to :resort
end
What I have a problem with is that if I update a photo I really need the
updated_at attribute on the Resort to change as well, how do I do this?
Use an after_update callback on Photo.
Thanks
bb
Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]Â
Ok.
Could you kindly clarify?
In my Photo model?
What would I put?
after_update… Do something with Resort.
Bb
bingo bob wrote:
Ok.
Could you kindly clarify?
In my Photo model?
What would I put?
after_update… Do something with Resort.
Right. Go read about ActiveRecord callbacks and all will become clear.
Bb
Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]Â
Marnen Laibow-Koser wrote:
bingo bob wrote:
Ok.
Could you kindly clarify?
In my Photo model?
What would I put?
after_update… Do something with Resort.
Right. Go read about ActiveRecord callbacks and all will become clear.
And, assuming you’re using a recent version or Rails you can ‘touch’
your models:
http://afreshcup.com/home/2009/4/19/touch-your-active-record-instances.html
Just to update and help anyone else.
As is mentioned above I simply touched and it simply worked.
Rails is beautiful sometimes :-).
class Photo < ActiveRecord::Base
belongs_to :resort, :touch => true
end
Thanks all.