[Catalyst] Database contents not displayed after hitting page refresh

ivorw m9tn-oh4c at xemaps.com
Wed Sep 3 16:59:00 BST 2008


Matt S Trout wrote:
> On Wed, Sep 03, 2008 at 09:04:23AM +0200, Emmanuel Quevillon wrote:
>   
>> You need to perform a search in your 'ShowData' function to get data
>> returned by the Resultset of your model 'Ttrack::Ttrack'.
>> At this time, $data is only a resultset object without any data in it.
>> Replace :
>>
>> my $data = $c->model('Ttrack::Ttrack');
>>
>> with
>>
>> my $data = $c->model('Ttrack::Ttrack')->search();
>>     
>
> No, don't do that.
>
> Those two lines are exactly equivalent except that ->search will cause
> a completely pointless clone of the resultset.
>
> $c->model('Ttrack::Ttrack') is -already- a resultset for the whole table.
>
> That's why there's something in there to search on.
>   
I presume that what ->search gives you depends on the context.

my @data = $c->model('Ttrack::Ttrack')->search;

will give you an array of row objects, though I would expect to use
->all as we are not specifying any search criteria to go into the where
clause.

In scalar context, ->find will get you just the row that you want.



More information about the Catalyst mailing list