Skip to content
This repository has been archived by the owner on Oct 16, 2018. It is now read-only.

Relationships between Payola models (plans, subscriptions, sales)

Nate Welling edited this page Aug 9, 2017 · 3 revisions

IMPORTANT NOTE: need to manually add these

User.rb (User model)

has_many :subscriptions, ->(sub), class_name: "Payola::Subscription", foreign_key: :owner_id

has_many :sales, ->(sub), class_name: "Payola::Sale", foreign_key: :owner_id


IMPORTANT NOTE: these ones are automatically added by Payola

has_many

belongs_to

Plan.rb (Payola::Plan)

has_many :subscriptions => @<plan_class>.subscriptions.first...

Subscription.rb (Payola::Subscription)

belongs_to :plan, polymorphic: true => @subscription.plan.name or @subscription.plan.stripe_id

belongs_to :owner, polymorphic: true

belongs_to :affiliate

has_many :sales, class_name: 'Payola::Sale', as: :owner

Sale.rb (Payola::Sale)

belongs_to :owner, polymorphic: true

belongs_to :product, polymorphic: true

belongs_to :coupon

belongs_to :affiliate