【发布时间】:2012-09-19 23:26:26
【问题描述】:
您好,我有三种模型:公司、计划和订阅,并具有以下关联
class Company < ActiveRecord::Base
has_one :plan, :through => :subscriptions
has_many :subscriptions
end
class Subscription < ActiveRecord::Base
belongs_to :plan
belongs_to :company
end
class Plan < ActiveRecord::Base
has_many :subscriptions
has_many :companies, :through => :subscriptions
end
我的申请计划“A”和计划“B”中有两个计划。计划“A”是免费的,“B”是收费的。现在我想让公司注册计划“A”和注册计划“B”的公司。
我想在我的模型中使用这些数据,我知道它们绝对是获得所有这些的简单方法,但是
我用过的每样东西都没有给我正确的数据。任何帮助都将不胜感激。
【问题讨论】:
标签: ruby-on-rails-3 associations has-many-through