[Catalyst] Perplexed Catalyst newbie

Sean McAfee eefacm at gmail.com
Sun Apr 19 20:05:25 GMT 2009


On Sun, Apr 19, 2009 at 12:41 PM, John Romkey <romkey at apocalypse.org> wrote:

> On Apr 19, 2009, at 3:22 PM, Sean McAfee wrote:
>
> [% FOR l IN lang; FOR s IN l.sources; s.termsets; END; END %]
>
> This TT snippet prints
>
> Quiz::Model::DB::Termset=3DHASH(0xcaa4d8)
> ARRAY(0xca4fb4)
>
> So now I'm completely confused.  Any help would be massively appreciated.
>
>
> This bit me a number of times when I was starting out with Catalyst.
>
> When you call $schema->resultset('Language') you're passing in to
> DBIx::Class::Schema the name of a ResultSet ('Language')
>
> When you call $c->model('Language') you're passing in to Catalyst the name
> of a Catalyst component which is a model. When the model corresponds to a
> DBIx::Class::Schema object it's a wrapper which passes stuff through.
>
> If Catalyst doesn't find a direct match for the name, it does a regular
> expression search across components to find one which matches. This often
> gives you unexpected results (to put it mildly). Recent revisions of
> Catalyst have issued loud warnings when it falls back to the regex search.
>
> To avoid the search, you'll have to qualify the model name. The last time=
 I
> wrote about this I screwed up the way that should be done, so I'll try to=
 do
> it better here. If the full name of your model is Quiz::Model::DB::Langua=
ge
> then you should pass DB::Language to $c->model(). That should avoid the
> regex search and get you back the resultset that you're looking for rather
> than the Catalyst model object that you're not.
>

I changed $c->model('Language') to $c->model('DB::Language') in my
controller, but as far as I can tell, nothing has changed.  I still get
Quiz::Model::DB::Language objects back, not Quiz::Schema::Language objects.
The snippet above produces the same output, including the oddball unblessed
array reference.

I only have three schema types in my project right now, with quite
dissimilar names, so there's not much ambiguity in a regex search, I would
imagine.

I still don't get how a DBIx::Class::ResultSet object's all() method can
return Catalyst objects in the first place.  $c->model('Language') and
$c->model('DB::Language') both return a DBIC ResultSet object.  Does DBIC
have setup hooks or something that let a caller wrap returned objects?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090419/22eac=
8ac/attachment.htm


More information about the Catalyst mailing list