[Catalyst] DBI search method problems

David Rio Deiros drio at console.net
Mon Feb 27 23:26:50 CET 2006


Hi There,

I have a very simple catalyst application that has two tables:

- contest (id,name)
- stationcontest (id, contest_id, name)

I have successfully create an scaffolding for both tables and now
I want to implement an action that will list all the contest that
match a particular condition.

In lib/dbtest/Controller/Contest.pm I add:

    sub test : Local {            
        my ( $self, $c, $id ) = @_;
        $c->stash->{item} = dbtest::Model::CDBI::Contest->search(id => 2);
        #$c->stash->{item} = dbtest::Model::CDBI::Contest->retrieve(2);
        $c->stash->{template} = 'Contest/test.tt';
    }

And this is the view's code:

[% item.id %]

When I point my browser to that action, nothing comes up. There
is for sure an entry in contest with id=2, and it has a name.

Notice that ->retrieve(2) works. But I cannot use that because 
I am going to use the code against stationcontest.contest_id and that
will return more than 1 row.

Also, I have tried an standalone application (outside the catalyst
framework) and this code works:

    foreach my $c ( testdbdrio::Contest->search(id => 2) ) {
        print $c->id, $c->name . "\n";
    }

What am I missing?

Thanks for your help,

David





More information about the Catalyst mailing list