Return 唯一用户不适用于 group_by

Return unique user doesn't work with group_by

我正在使用 ajax 数据table gem 来显示商店中的客户名称和总分。商店客户 table 看起来像这样。

store_id
client_id
total_points

但由于这将是一份报告,我不想向同一个客户展示两次,即使是在不同的商店。我正在尝试以下操作:

StoreClient.joins(:client).group(:client_id)

但是我得到这个错误:column "store_clients.id" must appear in the GROUP BY clause or be used in an aggregate function

如果我添加 store_clients id 结果与预期不同。

预期为:

client_id | store_id | total_points
   1           1          10
   1           2          20
   2           1          5
-----------------------------------
client_id | store_id | total_points
   1           1          10
   2           1          5

假设初始结果是一个存储在实例变量中的数组 @result 你可以获得这样的唯一结果:

@result.uniq {|o| o.client_id }