[Catalyst] DBI search method problems

David Rio Deiros drio at console.net
Tue Feb 28 00:38:54 CET 2006


On Mon, Feb 27, 2006 at 02:51:19PM -0800, Mark Blythe wrote:
> > $c->stash->{item} = dbtest::Model::CDBI::Contest->search(id => 2);
> 
> I believe the search routine returns an array in list context or an
> iterator object in scalar context.  Since you're calling it in scalar
> context, you're probably getting an iterator object.  Try changing it
> to:
> 
> ($c->stash->{item}) = dbtest::Model::CDBI::Contest->search(id => 2);

Andreas, Mark, Thanks for your answers.

After doing what Mark suggested it worked. After having that working 
I tried it with the real table:

lib/dbtest/Controller/Stationcontest.pm:

    sub listincontest : Local {
        my ( $self, $c, $contest_id ) = @_;
        ($c->stash->{stations}) =  
            dbtest::Model::CDBI::Stationcontest->search(contest_id => $contest_id);
        $c->log->info('--> drio: ' . $contest_id);
        $c->stash->{template} = 'Stationcontest/listincontest.tt';
    }

And the view:

   [% FOREACH s IN stations %]
                [% s.call_letters %] <br>
   [% END %]

That only shows 1 station but in the StationContest table I have:

sqlite> select * from stationcontest;
1|1|station1
2|2|station2
3|3|station3
4|4|station4
5|5|station5
6|1|station11
7|5|statioon55
8|5|station555

If I check the action,

I just get one row, station5. And I should get rows 5,7 and 8.

What is the proper way to retrieve the rows in the controller and 
iterate over them in the view?

Thanks,

David






More information about the Catalyst mailing list