updating parent resource whenever child is updated

I think the new functionality in edge rails will do what you want:


You say:

class Photo
  belongs_to :user, :touch => true

This way, whenever you save or delete a photo instance, it'll 'touch'
its parent user, and update the updated_at timestamp.

This will require you to upgrade to edge rails, though.

Looking at your attempt, though, I'm not sure this is what you want. Are
you also using the "updated_by" attribute of the photo to save the id of
the user that changed it?


Carlos Santana wrote:

Because the upduser is the same, it doesn't think that the object has really changed, so doesn't update the timestamps.

We had a similar problem where we needed to update the timestamps on the root object of a tree whenever anything in the tree changed. I ended up implementing a touch method on the object, and called that in a before_save hook.

  def touch
    orig_title = self.title
    self.title = ' '
    self.title = orig_title

  def after_save_hook

the edge rails code looks much nicer, but it will be a while before we can move to newer rails.