6

I expected the following to work:

class Attachment < ActiveRecord::Base
   belongs_to :attachable, :polymorphic => true, :touch => true
end

which I expect the associated objects to be "touched" when the Attachment record is saved or destroyed. It didn't work. Any ideas why?

Dia Kharrat
  • 5,948
  • 3
  • 32
  • 43

1 Answers1

9

Yes this should work. I have used this on several projects (2.3.x and 3.0.x) and it just works.

You may try to call touch manually like this: attachment.attachable.touch, then reload the attachable object and see if its updated_at field has been modified. If so, the :touch option should does that automatically.

James Chen
  • 10,794
  • 1
  • 41
  • 38
  • You're right; it's working for me now; I think it wasn't working for me because I forgot to set attr_accessible on the polymorphic relationship. – Dia Kharrat Feb 12 '11 at 09:03