On Sep 19, 5:11 pm, Kenny <[EMAIL PROTECTED]> wrote:
> What's the proper way to update a models timestamp when you add an
> object to one of it's associations?
>
> For example, if I have a model, Business, that has_many :addresses,
> when I add a new Address, I'd like the updated_at timestamp for the
> business object to get updated.
>
> Doing:
>
> @business.addresses.create(....)
>
> Does not update the updated_at timestamp for @business. What's the
> best way to get it to update?
>
> Thank you,
> Kenny
If you're using Rails 2.1 and have ActiveRecord::Base.partial_updates
= true, you can try this:
class Address
belongs_to :business
before_save :update_business
private
def update_business
if self.business && self.business_id_changed?
self.business.updated_at = Time.now
end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---