有沒有辦法來跳過更新協會與:touch
協會保存時?跳繩:觸摸協會保存一個ActiveRecord對象時
設置:
class School < ActiveRecord::Base
has_many :students
end
class Student < ActiveRecord::Base
belongs_to :school, touch: true
end
我想能夠做到像下面這樣在觸摸被跳過。
@school = School.create
@student = Student.create(school_id: @school.id)
@student.name = "Trevor"
@student.save # Can I do this without touching the @school record?
你能做到嗎?類似@student.save(skip_touch: true)
會很棒,但我還沒有找到類似的東西。
我不想使用像update_column
,因爲我不想跳過AR回調。
所以你平時想觸摸,但有時跳過觸摸? – AlexBrand 2013-04-25 18:12:58
確實如此。基本上我有一種情況,我正在更新所有觸摸相同關係的多個模型。我想在這種情況下避免碰觸。 – 2013-04-25 18:14:06