@signatures = Signature.where('action_id IN (?)', @actions).all

将有一个或多个签名的操作。
Signature id: 1, action_id: 1
Signature id: 2, action_id: 2
Signature id: 3, action_id: 1
Signature id: 4, action_id: 3
Signature id: 5, action_id: 2

什么ruby指令可以基于action\u id只提取单个案例?Signature.id = 4在上面的例子中

最佳答案

@signatures = Signature.where(action_id: @actions)
                       .group('action_id')
                       .select('id, count(action_id)')
                       .having('count(action_id) = 1')

关于ruby-on-rails - 从数组中提取单个案例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41098301/

10-10 01:47