[Dbix-class] Catalyst::Model::DBIC::Schema
Brandon Black
blblack at gmail.com
Wed Feb 8 18:01:58 CET 2006
On 2/8/06, Alex Kavanagh <alex at tinwood.homelinux.org> wrote:
> Hi
>
> At Tue, 7 Feb 2006 21:24:44 -0600,
> Brandon Black wrote:
> >
> > Catalyst::Model::DBIC::Schema exists now, although I haven't CPANed it
> > yet, awaiting more feedback, it may still need some tweaks to its
> > design.
> >
> > There's a snapshot available at
> > http://www.dtmf.com/Catalyst-Model-DBIC-Schema-0.01.tar.gz
>
> I'm getting very lost with all of the database classes! Have you got
> an example that uses:
>
> Catalyst
> DBIx::Class::Schema
> (and anything else relevant)
For a quick rundown (I know this isn't everything...):
Catalyst::Model::DBIC::Plain was originally for creating a
DBIx::Class::DB definition which also happened to be a Catalyst::Model
at the same time. Because it is extremely simplistic - the only code
in it, other than the Helper, is:
sub new {
my ( $self, $c ) = @_;
$self = $self->NEXT::new($c);
return $self;
}
I believe you can probably re-use it to do the same basic thing with
DBIx::Class::Schema, as long as you don't use ::Plain's Helper.
Someone could probably update the helper to switch to Schema mode
during class generation if they wanted to. You'd end up with a single
class definition which is simultaneously both a DBIx::Class::Schema
and a Catalyst::Model. This paragraph is all conjecture, as I haven't
tried it.
Cataylst::Model::DBIC::Schema is for creating a Catalyst Model class
which references a seperately defined DBIx::Class::Schema that might
reside elsewhere. The idea is that you create your
DBIx::Class::Schema in whatever way you see fit outside of Catalyst,
and this Model just points at that external Schema class and uses it
to construct a Catalyst model. It doesn't matter how the referenced
Schema is defined or created, so long as it is a valid
DBIx::Class::Schema class.
DBIx::Class::Schema::Loader is a way of defining a valid
DBIx::Class::Schema automatically in Loader-style from a database
connection. The resulting class is a valid DBIx::Class::Schema, just
like a manually generated one would be. Both Schema::Loader Schemas
and manual Schemas can be used with Catalyst::Model::DBIC::Schema.
One way to boil it down would be to say:
If you don't plan on using DBIx::Class in Schema mode (which is a
shame), you can ignore all the new stuff, and keep doing what you were
doing before with Catalyst::Model::DBIC or
Catalyst::Model::DBIC::Plain. This isn't the way into the future, but
it's simple.
If you are going the Schema route, your options are:
1) Manually define a DBIx::Class::Schema for your database, and...
a) come up with some custom method of your own for making it a
Catalyst Model too (actually, it just mostly works if you stick your
schema class definitions in MyApp/Model/, although sometimes are less
convenient than they should be, IIRC)
b) Use Catalyst::Model::DBIC::Plain to do it, just in a different
way than what the original Helper said
c) Use Catalyst::Model::DBIC::Schema, and tell it the name of your
Schema class (My::Schema or whatever) and let it set it up
2) Get an autoloaded Schema via DBIx::Class::Schema::Loader and use
Catalyst::Model::DBIC::Schema, and tell it the name of the Schema
class you made with Schema::Loader.
I've been considering today ways to optionally define the
Catalyst::Model::DBIC::Schema based on a dynamically create in-place
subclass of DBIx::Class::Schema::Loader for those using
Schema::Loader, which would make it a lot like the old
Catalyst::Model::DBIC (in that no external definitions are required,
just dsn/user/pass info). That would be yet another option, for those
that see no need to have a Schema class outside of Catalyst.
-- Brandon
More information about the Dbix-class
mailing list