Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DanielAmah/e4093c115aef028d94e8b6b6cdd4fc56 to your computer and use it in GitHub Desktop.
Save DanielAmah/e4093c115aef028d94e8b6b6cdd4fc56 to your computer and use it in GitHub Desktop.
## Plan + Subscription Relationship
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class Plan < ApplicationRecord
has_many :subscriptions
end
class Subscription < ApplicationRecord
belongs_to :plan
end
## If a User model is involved we could do this
## User + Plan + Subscription Relationship
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class User < ApplicationRecord
has_many :subscriptions
has_many plans, through: :subscription
end
class Plan < ApplicationRecord
has_many :subscriptions
has_many :users, through: :subscriptions
end
class Subscription < ApplicationRecord
belongs_to :user
belongs_to :plan
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment