gpt4 book ai didi

mysql - 使用 include 时 where 子句中的未知列错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:36:26 25 4
gpt4 key购买 nike

我有这个问题:

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::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 FROM recipes LEFT OUTER JOIN foos ON foos.id = recipes.foo_id WHERE foo.price = 0.0

为什么这不起作用?我正在使用其他一切都运行良好的查询。

最佳答案

您应该在 where 子句中将 foo:(您的关联名称)替换为 foos:(您的表的名称) .

includes(:foo).where(foos: { price: 0 })

关于mysql - 使用 include 时 where 子句中的未知列错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47655884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com