Ruby on rails 成对匹配同一表中两条记录的最佳方法
我有一个模型:Ruby on rails 成对匹配同一表中两条记录的最佳方法,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,我有一个模型: class Foo < ApplicationRecord belongs_to :other_foo, class_name: 'Foo' end class Foo
class Foo < ApplicationRecord
belongs_to :other_foo, class_name: 'Foo'
end
class Foo
如果我更新other\u foo
,我希望匹配的foo
实例也更新,以引用第一个实例
有没有更好的方法(除了回调)来实现这一点,或者我必须记住这一点并手动进行两次更新?使用
touch:true
class Foo < ApplicationRecord
belongs_to :other_foo, class_name: 'Foo', touch: true
end
class Foo
它如何解决我的问题?它只能更新
datetime
列。