繁体   English   中英

Rails 2.3.8 has_many:through

[英]Rails 2.3.8 has_many :through

我有3个桌子/班

   vectors, b_cells and transfections

他们像这样关联

    class BCell
    has_and_belongs_to_many :vectors ( JOIN ) 

    class Transfection
    has_and_belongs_to_many :vectors ( JOIN )

如何使用关联连接b_cell和转染? 我试过了

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

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

我正在使用Rails 2.3.8

我认为您对模型声明有疑问。 您可以尝试一下,看看是否能正常工作

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