按姓名分组

时间:2017-12-16 00:18:07

标签: ruby-on-rails group-by

如何通过传输名称而不是ID来订购?

顺序/ index.haml

=line_chart current_user
              .orders
              .group(:transport_id)
              .group_by_day(:created_at)
              .count,
            download: "boom"

关系

order.rb

belongs_to :user
belongs_to :transport

transport.rb

has_many :orders

这是我用它生成图形的库:https://www.chartkick.com/

谢谢!

1 个答案:

答案 0 :(得分:1)

window.location.assign("/path");
希望这会奏效。

使用此查询,它将按current_user.orders.joins(:transports).group(:transport_id).group_by_day(:created_at).order(transports::name).count

生成订单查询
相关问题