[Dbix-class] Catalyst Schema::Loader example?

Brandon Black blblack at gmail.com
Sat Mar 11 17:48:48 CET 2006


On 3/11/06, Vsevolod (Simon) Ilyushchenko <simonf at cshl.edu> wrote:
> Brandon (or anyone else),
>
> Can someone please post a Catalyst::Model::DBIC::Schema-based sample
> application? I got the new Schema::Loader to work on its own, but not
> under Catalyst so far.
>
> The Helpers are not helping much - it was not obvious, for example, that
> I need to use either of Catalyst::Helper::Model::DBIC::Schema or
> Catalyst::Helper::Model::DBIC::SchemaLoader, but not both.
>
> Also, it seems that the Helpers are creating an additional Schema class
> for each model class, duplicating the connection information in each of
> them (unless I completely misunderstand their usage).
>
> So, a working example that has a controller retrieve a model from the
> database would be very helpful.
>

Sorry for the lack of docs/examples.  As soon as I finish cleaning up
the DBIx::Class::Schema::Loader 0.03 stuff, I'll try to get a couple
of Catalyst examples going for people to look at (perhaps one very
simple one, and one that uses all of the features like ResultSet
methods in source class overlays on top of a Loader-based Schema,
custom relationship inflections, and whatnot).

Basically, if you already have a Schema class of some sort (be it a
manual one, or one defined via Schema::Loader), you can use
Catalyst::Helper::Model::DBIC::Schema, which will generate just a
single model-file which references your Schema class.  If you supply
connection information in the Schema itself, then supplying it again
to the helper/model is redundant and unneccesary (but if you didn't
specify a connection in the Schema class, then you need to specify one
to the helper / model-class).  Or in other words, the connection
information args to the helper are optional, but nothing's going to
work if you don't give the connect info to someone somewhere
(obviously).

The SchemaLoader helper is a seperate orthogonal helper designed to
make things "easy" like the original Catalyst::Helper::Model::DBIC,
where you don't need any pre-created classes of your own, you just
supply connection information to the helper script, and it gives you
an autoloaded model.  It does this by creating a
DBIx::Class::Schema::Loader-based Schema class for you, and then also
creating a Model class which references that Schema.

-- Brandon



More information about the Dbix-class mailing list