[Catalyst] Feelnig dumb: $c->model returns controller?

Jess Robinson castaway at desert-island.me.uk
Sun Feb 24 20:19:56 GMT 2008



On Sat, 23 Feb 2008, Alex Povolotsky wrote:

> Hello!
>
> I'm still writing my first Catalyst app; I'm beginning to love DBIx, and the 
> overall concept.
>
> But.
>
> my $lmodel = $c->model('Location');
> use Data::Dumper;
> print STDERR Dumper($lmodel);
> my $locs = $lmodel->search(undef); # Sort by follows, if required 
> Caught exception in Traffic2::C::Location->list "Can't locate object method 
> "search" via package "Traffic2::C::Location" at 
> /usr/local/traffic/Traffic2/script/../lib/Traffic2/C/Location.pm line 36."
>
> $VAR1 = bless( {
>                '_application' => 'Traffic2'
>              }, 'Traffic2::C::Location' );
>

You're just supplying the source name, which makes Catalyst guess which 
component you meant, since it looks at the controllers before the models, 
you get a controller.

You likely want: $c->model('DBIC::Location') instead, or whatever your 
actual model is called.

> With DailySummary, everything works just fine. I've added Location model 
> after DailySummary, but can it be the difference?...

Then you got lucky and that name is unique.

Jess



More information about the Catalyst mailing list