从查询无效的 belongs_to 加入

joins from belongs_to where query not working

我一直在尝试从 has_many table 加入,我能够像 订单 has_many order_items

Order.joins(:order_items).where(order_items: {name: 'something'})

但是如果我尝试从 belongs_to table 喜欢

OrderItem.joins(:order).where(order: {value: 'something'})

我尝试使用关键字 belongs_to 进行搜索,加入我无法得到它

虽然在 joins 中放置关联名称,但在 where 子句中您应该使用数据库 table 名称(orders - 复数)

OrderItem.joins(:order).where(orders: { value: 'something' })