[Rails] Re: combine 'group' and 'order' in joined tables

2012-10-29 Thread Javix
Finally, here is the solution I came to: @operations = Client.joins(:operations).select('clients.id,firstname, lastname, sum(total) as total').group('clients.id, firstname,lastname,total').paginate(page: params[:page]) It is not a will_paginate or smth eles problem, just PostgreSQL is more stri

[Rails] Re: combine 'group' and 'order' in joined tables

2012-10-27 Thread Javix
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 fr

[Rails] Re: combine 'group' and 'order' in joined tables

2012-10-26 Thread Javix
Even if the below solutions I found work in the console, it is no the case in the controller because the result is no more Array or AR relation but ActiveSupport::OrderedHash and 'paginate' method does not accept that: *1st way:* irb(main):019:0> cc = Operation.includes(:client).group('operati