I know this can be achieved using raw SQL
and Ecto.Adapters.SQL.query()
but what is the Ecto
way to it? Any help is highly appreciated, thank you.
SELECT COUNT(*) AS count, products.name AS product, categories.name AS category, stores.name AS store FROM "items"
INNER JOIN "stores" ON "stores"."id" = "items"."store_id"
INNER JOIN "products" ON "products"."id" = "items"."product_id"
INNER JOIN "categories" ON "categories"."id" = "products"."category_id"
WHERE "items"."store_id" IN (#{store_ids}) AND "items"."product_id"
IN (#{product_ids}) AND (products.category_id IN (#{category_ids}))
GROUP BY products.name, categories.name, stores.name
ORDER BY products.name