假设我有一个A型模型和一个B型模型,它的字段为a_id a2_id.我希望有类似的东西:
class B
belongs_to :a
belongs_to :a (using a2)
end
有谁知道我会怎么做?我试图使用B类链接我的数据库中的类似对象.
你可以这样做
class B
belongs_to :a
belongs_to :a2,foreign_key: 'a2_id',class_name: 'A'
end
原文链接:https://www.f2er.com/ruby/265342.html