jon*_*hue 0 ruby mysql sql activerecord ruby-on-rails
我有这个查询:
includes(:foo).where(foo: { price: 0 })
Run Code Online (Sandbox Code Playgroud)
我从一个名为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">
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Mysql2::Error: 'where 子句'中的未知列 'foo.price': SELECT
recipes。idAS t0_r0,recipes.foo_idAS t0_r1,recipes.parent_recipe_idAS t0_r2,recipes.nameAS t0_r3,recipes.descriptionAS t0_r4,quantities.slugAS t0_r5,recipes.created_atAS t0_r6,quantities.updated_atAS t0_r7,foos.idAS t1_r0,foos.category_idAS t1_r1,foos.priceAS t1_r2,foos.slugAS t1_r3,foos.created_atAS t1_r4,foos.updated_atAS t1_r5 从recipesLEFT OUTER JOINfoosONfoos。id=recipes.foo_id哪里foo。price= 0.0
为什么这不起作用?我正在使用其他一切正常的查询。
您应该在子句中将(foo:您的关联名称)替换为(foos:您的表的名称)where。
includes(:foo).where(foos: { price: 0 })
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
798 次 |
| 最近记录: |