1

I have been reading up on the use case for calling @model.touch and how you can have that bubble by passing , touch: true when setting up your associations in the model. I think I understand everything that is happening there.

What I wanted to ask is that if at no point in your code do you call .touch will having associations that include , touch: true do anything?

I am trying to familiarise myself with a new codebase that has a handful of places that have the association set to allow touch to bubble but there is nowhere in the code that .touch is ever called. I want to try and figure out if these are redundant properties of the association or if something else can hit .touch that would get use out of the bubbling of it.

Thanks in advance for any help.

Relevant Links

http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-touch

4

1 回答 1

1

干!

更多的挖掘让我明白了这一点:Rails 中的 belongs_to 的触摸何时触发?

其中包含以下引用:

:touch 如果为 true,则在保存或销毁此记录时,将触摸关联的对象(updated_at/on 属性设置为 now)。如果您指定了一个符号,那么除了 updated_at/on 属性之外,该属性还将使用当前时间进行更新。

保存/销毁的部分回答了我的问题。

于 2013-05-29T10:05:59.020 回答