我有这个问题:
includes(:foo).where(foo: { price: 0 })
我是从名为Recipe
的课程中调用它。
Foo的小数类型列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">
我收到此错误:
Mysql2 ::错误:未知栏&#39; foo.price&#39;在&#39; where子句&#39;:SELECT
recipes
。id
AS t0_r0,recipes
。foo_id
AS t0_r1,recipes
。{{1} } AS t0_r2,parent_recipe_id
。recipes
AS t0_r3,name
。recipes
AS t0_r4,description
。quantities
AS t0_r5,{{1} }。slug
AS t0_r6,recipes
。created_at
AS t0_r7,quantities
。updated_at
AS t1_r0,foos
。id
AS t1_r1,foos
。category_id
AS t1_r2,foos
。price
AS t1_r3,foos
。slug
AS t1_r4,foos
。created_at
AS t1_r5 FROMfoos
LEFT OUTER JOINupdated_at
ONrecipes
。foos
=foos
。id
WHERE {{1} }。recipes
= 0.0
为什么这不起作用?我正在使用其他查询,这些查询都完美无缺。
答案 0 :(得分:4)
您应该在foo:
子句中将foos:
(您的关联名称)替换为where
(您的表名)。
includes(:foo).where(foos: { price: 0 })