I have an ItemsDesign model with a HABTM with ItemsCategory and Color, belongs to ItemsStyle and Store
The Page is set up where you would select a category or subcategory. then you would have the ability to filter by color, store, style and price (price is a column in the items_design table)
I'm a little stuck on how to write this query. this is what I have so far. So when I introduced color into the mix it returns nothing.
Right now I'm just hard coding values in to get it work. Of course I need this to work with params.
@products = Kaminari.paginate_array(
ItemsDesign.joins(:items_categories, :colors)
.where('items_categories.id' => @category, 'colors.name' => :white))
.page(params[:page]).per(48)
Here's the sql
SELECT "items_designs".*
FROM "items_designs"
INNER JOIN "items_categories_items_designs"
ON "items_categories_items_designs"."items_design_id" = "items_designs"."id"
INNER JOIN "items_categories"
ON "items_categories"."id" = "items_categories_items_designs"."items_category_id"
INNER JOIN "colors_items_designs"
ON "colors_items_designs"."items_design_id" = "items_designs"."id"
INNER JOIN "colors" ON "colors"."id" = "colors_items_designs"."color_id"
WHERE "items_categories"."id" IN (1, 5, 10, 11, 12, 6, 13, 14, 15, 7, 16, 17, 18, 19, 8, 20, 21, 22, 9, 23, 24, 25, 104)
AND "items_designs"."colors" = 'white'):