0
我有A
模型,B
模型和Connecting
模型。通过第三表加入的关联
A和B有一个con_id
列,它是连接模型中的ID。
我试着做到以下几点: 在答:
has_many :connectings
has_many : bs, :through => connectings
在B:
has_many :connectings
has_many :as, :through => connectings
然后在连接:
belongs_to :as
belongs_to :bs
然后试图使连接和包括查询:
A.joins(:bs).includes(:connectings).where("my_condition")
失败。
我在做什么错?
在你的'Connecting'模型使它奇异。 'belongs_to:a#外键 - a_id' 'belongs_to:b#外键 - b_id'。此外,如果这是您的实际代码,则A模型中的':'和'bs'之间会有一个空格。以下是一些[文档]的参考(http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord:Associations::ClassMethods-label-Many-to-many) – user3366016