[Dbix-class] Using { count => 'me.list_id' } with AS hack from the FAQ (TYPO in my example)

John Napiorkowski jjn1056 at yahoo.com
Tue Oct 10 16:58:44 CEST 2006


Hi,

my example was from an older build with a typo:

use:

my $newest = $c->model('db::members')->search({},
$params);

not:

my $newest = $c->model('db::members')->search(undef,
$params);

Putting undef there seems to work but the
documentation specifies for you to use an empty hash
ref so there must be a reason.  Good luck,

John

--- John Napiorkowski <jjn1056 at yahoo.com> wrote:

> --- Ash Berlin <ash at cpan.org> 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
> 
> I have something similar where I try to get the max
> value for a given column and I also had trouble
> getting it to work.  The key was to remember that
> you
> have a resultset returned, not a row.  Here's how I
> do
> it (It's a catalyst based example but should work
> similarly:
> 
> my $params = { 
> 	
>  select	=> {MAX => 'updated' }, 
>  as	=> 'updated', 	
> }
> 
> my $newest = $c->model('db::members')->search(undef,
> $params);
> 
> my $updated = newest->single->updated;
> 
> You have to remember that search returns a resultset
> which you need to iterate against, even if there is
> one value.
> 
> you could also (probably) do:
> 
> my ($first) =
> $c->model('db::members')->search(undef,
> $params)->all;
> 
> my $updated = $first->updated;
> 
> I just usually stay away from ->all;
> 
> --john
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
> _______________________________________________
> 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/dbix-class@lists.rawmode.org/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Dbix-class mailing list