简体   繁体   English

Rails 2.3.8 has_many:through

[英]Rails 2.3.8 has_many :through

I have 3 Tables/Classes 我有3个桌子/班

   vectors, b_cells and transfections

They are associated like this 他们像这样关联

    class BCell
    has_and_belongs_to_many :vectors ( JOIN ) 

    class Transfection
    has_and_belongs_to_many :vectors ( JOIN )

How do I connect b_cells and transfections using the associations? 如何使用关联连接b_cell和转染? I tried 我试过了

    class BCell
    has_many :transfections, :through => :vectors

    class Transfection
    has_many :b_cells, :through => :vectors

I am using rails 2.3.8 我正在使用Rails 2.3.8

I think you are having a problem with the model declaration. 我认为您对模型声明有疑问。 Can you try this and see if it will work 您可以尝试一下,看看是否能正常工作

class BCell < ActiveRecord::Base
    has_many :vectors 
    has_many :transfections, :through => :vectors
end

class Transfection < ActiveRecord::Base
    has_many :vectors
    has_many :b_cells, :through => :vectors
end

class vectors < ActiveRecord::Base
    belongs_to :b_cell
    belongs_to :transfection
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM