这就是四个模型的架构:http://pastie.org/1576759
计划表存储有关实际计划的所有数据。订阅每个月存储用户“重新订阅”该服务。该交易存储与付款相关的信息。
协会如何在模型之间起作用?
E.g。用户:belongs_to plan,:through => :订阅?
订阅“has_many”:计划?
我对Rails和关联方面的联系方式有点模糊。
答案 0 :(得分:3)
class Subscription < ActiveRecord::Base
belongs_to :user
belongs_to :plan
end
class User < ActiveRecord::Base
belongs_to :plan
has_many :subscriptions (or has_one, if a user only has 1 subscription at a time)
has_many :transactions
end
class Transaction < ActiveRecord::Base
belongs_to :user
belongs_to :plan
end
class Plan < ActiveRecord::Base
has_many :subscriptions
has_many :users
end