Help "ruby-fying" this SQL
I just need some help to finish turning this SQL :
SELECT us.name, pt.task, sum(hours)
FROM records
INNER JOIN project_tasks pt ON records.task_id = pt.id
INNER JOIN users us ON records.user_id 开发者_StackOverflow中文版= us.id
GROUP BY user_id, task
into Ruby SQL similar to this:
test = Record.sum( :hours ,
:joins => :project_task,
:joins => :user,
:conditions => {""} )
ive got this far above but im having trouble working out the conditions. i got the above from converting the SQL to this:
test = Record.select( "name, task, sum(hours)").joins( :project_task).joins( :user).group("user_id, task" )
im new to Ruby so any help would be great
Old style variant will be:
Record.find(:all,
:select => 'name, task, sum(hours)',
:joins => 'INNER JOIN project_tasks pt ON records.task_id = pt.id INNER JOIN users us ON records.user_id = us.id',
:group => 'user_id, task')
精彩评论