Skip to content

Instantly share code, notes, and snippets.

@theHamdiz
Last active December 1, 2016 20:04
Show Gist options
  • Select an option

  • Save theHamdiz/aaab117a1292c6519fe8c0cebfd07e22 to your computer and use it in GitHub Desktop.

Select an option

Save theHamdiz/aaab117a1292c6519fe8c0cebfd07e22 to your computer and use it in GitHub Desktop.
Product.joins(:categories).where(category: { id: [1,2,3,4,5] }).where('products.name like ?', "%ant%")
Product Load (0.5ms) SELECT "products".* FROM "products" INNER JOIN "product_categories" ON "product_categories"."product_id" = "products"."id" INNER JOIN "categories" ON "categories"."id" = "product_categories"."category_id" WHERE "category"."id" IN (1, 2, 3, 4, 5) AND (products.name like '%ant%')
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: category.id: SELECT "products".* FROM "products" INNER JOIN "product_categories" ON "product_categories"."product_id" = "products"."id" INNER JOIN "categories" ON "categories"."id" = "product_categories"."category_id" WHERE "category"."id" IN (1, 2, 3, 4, 5) AND (products.name like '%ant%')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment