【发布时间】:2010-01-02 10:54:03
【问题描述】:
现在我正在为我的两个模型使用 has_and_belongs_to_many 关联,如下所示:
class Books < ActiveRecord::Base
has_and_belongs_to_many :publishers
end
class Publisher < ActiveRecord::Base
belongs_to :publishing_company
has_and_belongs_to_many :books
end
您会注意到每个出版商都属于一家出版公司:
class PublishingCompany < ActiveRecord::Base
has_many :publishers
end
我的目标是建立一个允许我这样做的协会:
PublishingCompany.find(1).books
这对于传统的 RoR 关联是否可行?
【问题讨论】:
标签: ruby-on-rails associations