ActiveRecord Chartkick

ActiveRecord Chartkick

嗨,我正在为 Chartkick 开发 ActiveRecord,因为我还在学习

此刻 我写了预订表的代码

<%= column_chart Reservation.where(:user_id => current_user.id, :status => 2).group(:tool_id).sum(:total) %>

显示正常

然而,红色突出显示是正确的,但我希望将此“:tool_id”更改为更多文本,例如 "resrvation.tool_id" 与 "tool.brand"[=14= 的关系]

当我写入数据时 table 并且它正确显示

          <td><%= link_to reservation.tool.id, reservation.tool, target: :_blank %></td>
          <td><%= reservation.tool.brand %></td>

所以我想知道如何调整这个图表作为一个组(:tool_id)更改为tool.brand

Reservation.joins(:tools)
           .where(user_id: current_user.id, status: 2)
           .group('tools.brand')
           .sum('reservations.total)

这将根据名称而不是 id 进行分组,这样您就可以计算出所有具有相同名称的工具 :D