Last active
May 1, 2020 14:43
-
-
Save npassaro/4bec46845c7170e54ece14b93475ca5d to your computer and use it in GitHub Desktop.
Models
This file contains 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
class BadCompanion < Green | |
has_many :companionships, as: :companion | |
has_many :greens, through: :companionships | |
end |
This file contains 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
class Companionship < ApplicationRecord | |
belongs_to :green | |
belongs_to :companion, polymorphic: true | |
end |
This file contains 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
class GoodCompanion < Green | |
has_many :companionships, as: :companion | |
has_many :greens, through: :companionships | |
end |
This file contains 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
class Green < ApplicationRecord | |
has_many :companionships | |
has_many :bad_companions, through: :companionships, source: :companion, source_type: 'BadCompanion' | |
has_many :good_companions, through: :companionships, source: :companion, source_type: 'GoodCompanion' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment