[Dbix-class] Issues with using the as=>[...] parameter
John Napiorkowski
jjn1056 at yahoo.com
Thu Nov 2 23:19:58 GMT 2006
Hi,
Not sure if I am doing this correctly. I am trying to
order a result by the count of something but the 'as'
parameter doesn't seem to do what I think it should
do:
Here is my code:
$image_album_link->result_source->storage->debug(1);
my $result = $image_album_link->search({}, {
select => [ 'album_id', 'user_id', {
COUNT=>'image_id'}],
as => [ qw/album_id user_id image_count/ ],
group_by => [ qw/album_id user_id/ ],
order_by => 'image_count DESC',
rows => 25,
});
This gives me the following error:
"DBIx::Class::ResultSet::next(): Error executing
'SELECT album_id, user_id, COUNT( image_id ) FROM
image_album_link me GROUP BY album_id, user_id ORDER
BY image_count DESC LIMIT 25': DBD::mysql::st execute
failed: Unknown column 'image_count' in 'order clause'
[for Statement "SELECT album_id, user_id, COUNT(
image_id ) FROM image_album_link me GROUP BY album_id,
user_id ORDER BY image_count DESC LIMIT 25"] at
/usr/lib/perl5/site_perl/5.8.5/DBIx/Class/Storage/DBI.pm
line 771."
It appears that the 'as' parameter is not setting the
alias in the way I would expect. I'm sure I'm just
doing something silly wrong. The SQL I am trying to
make is:
SELECT album_id, user_id, COUNT( image_id ) as
image_count FROM image_album_link me GROUP BY
album_id, user_id ORDER BY image_count DESC LIMIT 25
I know this is a good SQL statement since I can run it
fine from the console.
What I get from the debug output is:
SELECT album_id, user_id, COUNT( image_id ) FROM
image_album_link me GROUP BY album_id, user_id ORDER
BY image_count DESC LIMIT 25
Can anyone spot what I am doing wrong here?
Thanks!
--john
____________________________________________________________________________________
Access over 1 million songs - Yahoo! Music Unlimited
(http://music.yahoo.com/unlimited)
More information about the Dbix-class
mailing list