Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 成对匹配同一表中两条记录的最佳方法_Ruby On Rails_Activerecord - Fatal编程技术网

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
列。