I have a query:
@clients = Client.where(location_id: location).includes(:check_ins, :payments, :purchases).where("check_ins.created_at > ?", start_date).references(:check_ins)
that returns an ActiveRecord::Relation array of clients. Each client has_many :payments and each payment has an :amount.
For each client in the ActiveRecord::Relation, I'd like to include the sum of their payment amounts client.payments.sum(:amount). How can I get that returned in the array?
© 2016 Powered by mzan.com design MATCHINFO