Activerecord 如何使用枚举查询活动记录

Activerecord 如何使用枚举查询活动记录,activerecord,rails-activerecord,Activerecord,Rails Activerecord,我正在尝试此查询,但它不起作用: OrderFulfillment.where(shopper_id: shopper.id, fulfillment_status: [:fulfillment_requested_assignment, :fulfillment_assigned, :fulfillment_shopping]) 我不知道为什么,但我无法使用枚举进行查询 OrderFulfillment.where(shopper_id: shopper.id,

我正在尝试此查询,但它不起作用:

OrderFulfillment.where(shopper_id: shopper.id, fulfillment_status:  [:fulfillment_requested_assignment, :fulfillment_assigned, :fulfillment_shopping])
我不知道为什么,但我无法使用枚举进行查询

OrderFulfillment.where(shopper_id: shopper.id, 
                       fulfillment_status: OrderFulfillment
                         .fulfillment_statuses
                           .values_at([:fulfillment_requested_assignment,
                                       :fulfillment_assigned,
                                       :fulfillment_shopping]))

Rails不够聪明,无法知道您正在传递的是键而不是值,因此当您像这样直接传递状态时,它正在寻找错误的值(它将它们更改为
null
,因为它不理解)。枚举在物理上存储为整数,因此在查询中实际需要使用整数。因此,您可以使用Rails提供的
fulfillment\u status
方法获取枚举的键/值对的散列,然后使用散列的
values\u at
方法获取传入的键数组的值。

出现了哪些错误?服务器日志上写了什么?