Dia*_*rat 5 ruby-on-rails polymorphic-associations belongs-to
我希望以下工作:
class Attachment < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true, :touch => true
end
Run Code Online (Sandbox Code Playgroud)
我希望在保存或销毁附件记录时"触摸"相关对象.它没用.有什么想法吗?
是的,这应该工作.我已经在几个项目(2.3.x和3.0.x)上使用它,它只是工作.
您可以尝试像这样手动调用touch:attachment.attachable.touch,然后重新加载可附加对象并查看其updated_at字段是否已被修改.如果是这样,:touch选项应该自动执行.