I’m working on a site which has members. Each member has a subscription. For a subscription a member needs to choose a plan of which there are 3.
Is this correct way to do the association
class Member < ActiveRecord::Base
has_one :plan, :through => :subscription
end
class Subscription < ActiveRecord::Base
belongs_to :member
has_many :plans
end
class Plan < ActiveRecord::Base
belongs_to :subscription
end
Then maybe something like this
member.plan
would be the plan a member is subscribed to.
If a member can belong to one plan at a time you can redo your models as follows:
Other solution is to avoid the
Subscriptionmodel altogether by adding aplan_idcolumn tomemberstable.