[Dbix-class] DBIx::Class::Schema-ORDER_BY

Touya dong.yi at adways.net
Wed Mar 8 02:43:22 CET 2006


    I have got a problem when I use DBIx::Class->resultset->search({},{order_by=>[...]})

SQL in MySQL which works well:
select name,sum(score) as total_score from stu_score group by stu_id order by total_score desc

I wanted to implement it using DBIC,but I found mistake here.

code:
$schema->resultset('StuScore')->search(
  {},
  {
    select=>['name',{'sum'=>'score'}],
    as=>['name','total_score'],
    group_by=>['stu_id'],
    order_by=>['total_score desc'],
  },
);

Error:
DBD::mysql::st execute failed: Unknown column 'total_score' in 'order clause' at C:/Pe rl/site/lib/DBIx/Class/Storage/DBI.pm line 387.

Tracing SQL:
SELECT name,SUM( score ) FROM stu_score GROUP BY stu_id ORDER BY total_score desc

Why there is no 'as' in SQL?So that I cann't order by total_score...
How can I use order by in this case?

Thank you all:)


Touya
Adways Co.Ltd
Telephone: (86-21)63410128-212
FAX: (86-21)63410208
Email: dong.yi at adways.net
http://dev.adways.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060308/2cd5ceae/attachment.htm 


More information about the Dbix-class mailing list