I have the following models
Items
Customisations
Property Maps
with Associations like so –
**Customizations**
belongs_to :item
has_many :property_maps, as: :mappable
**Items**
has_many :customizations
has_many :property_maps, as: :mappable
**Property Maps**
belongs_to :mappable, polymorphic: true
I’ve implemented a pretty decent filtering system taking into consideration just Items and properties like so –
def self.filter_in_properties(property_ids, group_name)
joins(:property_maps).joins('JOIN property_maps '+group_name+' ON '+group_name+'.mappable_id = items.id AND '+group_name+'.property_id IN ('+property_ids.to_s.tr('[', '').tr(']', '').tr('"', '') +')')
end
and I call them in the controller like so –
@items_without_pagination.filter_in_properties(params[:color_filter], 'color_filter').uniq
How can I do build out a filtering system so that when for example a user searches for the color red, it not only returns items that have the property red but also return items which have customizations with the property red?