Skip to content

Instantly share code, notes, and snippets.

@meierjan
Created November 28, 2014 20:07
Show Gist options
  • Save meierjan/0758f1eaa2f736693f7b to your computer and use it in GitHub Desktop.
Save meierjan/0758f1eaa2f736693f7b to your computer and use it in GitHub Desktop.
class Feature < ActiveRecord::Base
has_many :flat_features
has_many :flats, through: :flat_features
end
class FlatFeature < ActiveRecord::Base
belongs_to :flat
belongs_to :feature
end
class Flat < ActiveRecord::Base
has_many :flat_features
has_many :features, through: :flat_features
def full_feature_list()
Feature.all.map { |feature| [feature, self.features.include? feature ] }
end
def has_feature(feature)
self.features.include? feature
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment