Reputation: 1467
I have this query:
includes(:foo).where(foo: { price: 0 })
I am calling it from a class called Recipe
.
Foo's have the decimal type column price
:
>> Recipe.first.foo
=> #<Foo id: 1, price: #<BigDecimal:928b000,'0.0',9(18)>, slug: "something", created_at: "2017-12-05 07:54:29", updated_at: "2017-12-05 13:00:51">
I get this error:
Mysql2::Error: Unknown column 'foo.price' in 'where clause': SELECT
recipes
.id
AS t0_r0,recipes
.foo_id
AS t0_r1,recipes
.parent_recipe_id
AS t0_r2,recipes
.name
AS t0_r3,recipes
.description
AS t0_r4,quantities
.slug
AS t0_r5,recipes
.created_at
AS t0_r6,quantities
.updated_at
AS t0_r7,foos
.id
AS t1_r0,foos
.category_id
AS t1_r1,foos
.price
AS t1_r2,foos
.slug
AS t1_r3,foos
.created_at
AS t1_r4,foos
.updated_at
AS t1_r5 FROMrecipes
LEFT OUTER JOINfoos
ONfoos
.id
=recipes
.foo_id
WHEREfoo
.price
= 0.0
Why isn't this working? I am using other queries which are all working perfectly fine.
Upvotes: 0
Views: 1509
Reputation: 44581
You should replace foo:
(the name of your association) with foos:
(the name of your table) in the where
clause.
includes(:foo).where(foos: { price: 0 })
Upvotes: 6