ruby-on-rails - rails 内的嵌套值查询 where
问题描述
查询
@products = @products.offset(offset).limit(@limit).where(status: "visible").where.not(inventory: [nil, {}])
我该如何添加
where.not((product.inventory.length == 1 and product.inventory.first[1]["quantity"].to_i == 0)))))
?
即如何检查财产的长度,inventory
如果1检查第一个条目的数量,并满足上述条件?
解决方案
使用 jsonb 运算符
@products =
@products
.offset(offset)
.limit(@limit)
.where(status: "visible")
.where.not(inventory: [nil, {}])
.where.not("ARRAY(select (jsonb_each(inventory)).value->>'quantity' as integer)='{0}'")
推荐阅读
- ios - 在几秒钟内多次调用 Healthkit 后台交付
- python - Turning int into str to run requests from api
- ios - IOS项目目标中的多个Objective C桥接头
- javascript - 如何获得第一个解决的递归承诺
- c# - Is there a memory efficient way to use 'using' within a recursive function when e.g. writing lines to a file?
- python - Adding a key on a density graph with Pandas
- reactjs - React/NPM dependecy error on create-react-app project
- flutter - @protected 在飞镖中是什么意思
- python - 线程错误:NameError:未定义名称“datelabelstringvar”
- javascript - 使用搜索词过滤对象数组会得到“TypeError:includes is not a function”