With the below relationship in mind:
class Style < ActiveRecord::Base
has_many :stylefeatures, :dependent => :destroy
has_many :features, :through => :stylefeatures
end
class Stylefeature < ActiveRecord::Base
belongs_to :style
belongs_to :feature
end
class Feature < ActiveRecord::Base
has_many :stylefeatures, :dependent => :destroy
has_many :styles, :through => :stylefeatures
end
How would I most efficiently add indexes to speed up this method in the Style model:
def has_feature? (arg)
self.features.where(:name=>arg).exists?
end