开发者

Can "touch" be used on a belongs_to polymorphic relationship in Rails?

开发者 https://www.devze.com 2023-02-09 22:00 出处:网络
I expected the following to work: class Attachment < ActiveRecord::Base belongs_to :attachable, :polymorphic => tr开发者_JAVA百科ue, :touch => true

I expected the following to work:

class Attachment < ActiveRecord::Base
   belongs_to :attachable, :polymorphic => tr开发者_JAVA百科ue, :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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消