Skip to content

Instantly share code, notes, and snippets.

@jeffreyjurgajtis
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreyjurgajtis/f8587c852d2a229f4763 to your computer and use it in GitHub Desktop.
Save jeffreyjurgajtis/f8587c852d2a229f4763 to your computer and use it in GitHub Desktop.
FeatureModeling
# models/feature.rb
class Feature
validates :name, presence: true, uniqueness: true
end
# models/feature_provider.rb
class FeatureProvider
belongs_to :feature
belongs_to :provider, polymorphic: true
validates_presence_of :feature, :provider
end
# models/apartment.rb
class Apartment
has_many :feature_providers, as: :provider, dependend: :destroy
has_many :features, through: :feature_providers
end
# models/neightborhood.rb
class Apartment
has_many :feature_providers, as: :provider, dependend: :destroy
has_many :features, through: :feature_providers
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment