Home Return calculated value with rails query
Reply: 0

Return calculated value with rails query

user613
1#
user613 Published in June 23, 2018, 4:20 am

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.346644 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO