[Catalyst] DBI search method problems

Drew Taylor taylor.andrew.j at gmail.com
Wed Mar 1 15:12:56 CET 2006


On 2/27/06, Mark Blythe <list at markblythe.com> wrote:
> You should probably use the iterator if you want to access them all.
> You start by assigning to a scalar, which returns an iterator object:
>
> $c->stash->{stations} =
> dbtest::Model::CDBI::Stationcontest->search(contest_id =>
> $contest_id);

Just to show the other side of the coin, you could also do:

$c->stash->{stations} = [
dbtest::Model::CDBI::Stationcontest->search(contest_id =>$contest_id)
];

This uses the list context to capture an arrayref of the individual
objects. In your temple you would go back to the FOREACH you were
using before. If you will have lots of objects, then the iterator is
probably more efficient. For most of my apps I often use the
individual objects because I generally have just a few of them.

Remember, with perl (and Catalyst and CDBI) TIMTOWTDI. :-)

Drew
--
----------------------------------------------------------------
 Drew Taylor                 *  Web development & consulting
 Email: drew at drewtaylor.com  *  Site implementation & hosting
 Web  : www.drewtaylor.com   *  perl/mod_perl/DBI/mysql/postgres
 ----------------------------------------------------------------



More information about the Catalyst mailing list