Last active
May 16, 2020 10:27
-
-
Save maxcal/385a5c4f8d85557887602538c4cde5a2 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
class AddFeatureGroupIdToFeatures < ActiveRecord::Migration[6.0] | |
def change | |
add_refererence :features, :feature_group, foreign_key: true | |
end | |
end |
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
class Feature < ApplicationRecord | |
has_many :products, through: :product_features | |
has_many :product_features | |
belongs_to :feature_group | |
end | |
class FeatureGroup < ApplicationRecord | |
has_many :features | |
has_many :products, through: :features | |
end | |
class ProductFeature < ApplicationRecord | |
belongs_to :feature | |
belongs_to :product | |
# default scope should be avoided | |
end | |
class Product < ApplicationRecord | |
has_many :product_features | |
has_many :features, through: :product_features | |
has_many :feature_groups, through: :features | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment