Created
May 29, 2020 17:48
-
-
Save DanielAmah/37a0a0fd5f5fde0f4b37b2cadc151592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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