Ruby on Rails Saturday, October 27, 2012

Some correction has been applied:

@operations = Client.joins(:operations).select('firstname, lastname, sum(total) as total').group('clients.id, firstname,lastname').paginate(page: params[:page])


The same but in SQL:

select clients.firstname, clients.lastname, sum(operations.total) as total from "clients"
INNER JOIN "operations" ON "operations"."client_id" = "clients"."id" GROUP BY clients.id, clients.firstname,
clients.lastname order by clients.lastname

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/1c11ACVX4BsJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment