Mysql 使用includes时where子句中出现未知列错误

Mysql 使用includes时where子句中出现未知列错误,mysql,sql,ruby-on-rails,ruby,activerecord,Mysql,Sql,Ruby On Rails,Ruby,Activerecord,我有一个疑问: includes(:foo).where(foo: { price: 0 }) 我是从一个叫“菜谱”的课上叫它的 Foo具有十进制类型的列价格: 我得到这个错误: Mysql2::错误:“where子句”中的未知列“foo.price”:选择recipes.id为t0_r0,recipes.foo_id为t0_r1,recipes.parent_recipe_id为t0_r2,recipes.name为t0_r3,recipes.description为t0_r4,quanti

我有一个疑问:

includes(:foo).where(foo: { price: 0 })
我是从一个叫“菜谱”的课上叫它的

Foo具有十进制类型的列价格:

我得到这个错误:

Mysql2::错误:“where子句”中的未知列“foo.price”:选择recipes.id为t0_r0,recipes.foo_id为t0_r1,recipes.parent_recipe_id为t0_r2,recipes.name为t0_r3,recipes.description为t0_r4,quantities.slug为t0_r5,recipes.created_为t0_r6,quantity.updated_为t0_r7,foos.id为t1_r0,foos.id为t1_r0,foos.category为t1_r1,foos.price作为t1_r2,foos.slug作为t1_r3,foos.created作为t1_r4,foos.updated作为t1_r5,从配方左侧外部连接foos.id=recipes.foo_id,其中foo.price=0.0

为什么这不起作用?我正在使用其他查询,它们都工作得非常好。

您应该在where子句中将foo:your association的名称替换为foos:your table的名称

您应该在where子句中将您的关联名foo替换为表名foos


渴望加载:foo.wherefoo:{price:0}或包含:foo.wherefoo:{price:0}。引用:foos给我相同的错误。uhh。。很抱歉,我不需要添加引用,因为我没有直接使用SQL,但我错过了您已将foo:更改为foos:。它正在工作。谢谢你的帮助!渴望加载:foo.wherefoo:{price:0}或包含:foo.wherefoo:{price:0}。引用:foos给我相同的错误。uhh。。很抱歉,我不需要添加引用,因为我没有直接使用SQL,但我错过了您已将foo:更改为foos:。它正在工作。谢谢你的帮助@mudasobwa给我的错误与全球化gem的错误相同。@mudasobwa给我的错误与全球化gem的错误相同。
>> 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">
includes(:foo).where(foos: { price: 0 })