On 10/10/06, Ash Berlin <[EMAIL PROTECTED]> wrote:
> Kevin Old wrote:
> > Hello everyone,
> >
> > I'm trying to use the hack defined in the FAQ for "sort my results
> > based on fields I've aliased using as" with the following statement
> > which includes a count.
> >
> > $schema->resultset("MyTable")->search(undef, { select => [ { count =>
> > 'list_id'} ], as => [ 'list_count' ] });
> >
> > Can someone give me the syntax for this statement for the hack?  I've
> > tried just about every combination of inserting \' as list_count' but
> > nothing seems to work.
> >
> > Any help is greatly appreciated,
> > Kevin
> >
> Define doesn't work.
>
> If you mean $rs->list_count says no such method, then yes - it doesn't
> create an accessor for it. to $rs->get_column('list_count')
>
> If you mean the query doesn't run, then please tell us what error it gives.
>
> Ash

Hi Ash,

This is what I'm trying to add to my resultset:

>From 
>http://search.cpan.org/~danieltwc/DBIx-Class-0.07002/lib/DBIx/Class/Manual/FAQ.pod:
.. sort my results based on fields I've aliased using as?

    You don't. You'll need to supply the same functions/expressions to
order_by, as you did to select.

    To get "fieldname AS alias" in your SQL, you'll need to supply a
literal chunk of SQL in your select attribute, such as:

     ->search({}, { select => [ \'now() AS currenttime'] })

    Then you can use the alias in your order_by attribute.

I am able to get to $l->list_count.  The problem is I can't get the
SQL to say "AS list_count" which is needed for my order by and group
by statements.

The hack above in the FAQ tells how to do this, but like I said
before, I can't get the syntax defined in the FAQ to work with the
"select => [ { count => 'list_id' } ]".

According to the docs, this should work (by work I mean produce
"select count (list_id) as list_count):

select => [ { count => 'list_id' }, \' AS list_count']

Of course it fails on syntax, so I'm at a loss.

Any help is appreciated!

Kevin
-- 
Kevin Old
[EMAIL PROTECTED]

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to