[Catalyst] Using model layer with DBIC::Schema

Matt S Trout dbix-class at trout.me.uk
Tue Jun 27 22:48:09 CEST 2006


Dr. Jennifer Nussbaum wrote:
> Hi,
> 
> im just moving some work to DBIx::Class (which im really liking!), and i 
> have a
> question about setting up my Schemas.
> 
> The docs for Catalyst::Plugin::DBIC::Schema talk a lot about setting up your
> DBIC classes in MyApp::Schema so you can use it on it's own, and then
> creating MyApp::Model::FilmDB, which calls MyApp::Schema::Film as it's
> Schema Class. So you then have Model::Film which is in Catalyst but doesnt
> really exists, it's a creation of the Schema.
> 
> i want to know the best way to set up a REAL Model::Film with DBIC. That is,
> i have a Catalyst Controller that needs a model to do things relating to 
> CATALYST. i want my controller to pass $c to a model that can do a bunch of
> Catalyst related things, and IT calls my DBIC class. In other words i 
> want a
> model layer in Catalyst that calls my fixed, not-Catalyst model in 
> MyApp::Schema.
> 
> Is there a recomended way of doing this with the Catalyst plugin or a 
> recomended
> way of doing it from scratch?

If it'd be sufficient to do it by subclassing, then creating 
MyApp/Model/DB/Film.pm etc. and putting the methods in there should work fine 
(the superclasses will be set by C::M::DBIC::Schema)

If you want an entire layer in between (which I usually do), then your best 
bet is to either

(a) create a C::M::DBIC::Schema model normally, then add your own additional 
model classes that call them via $c->model (e.g. have your C::M::DBIC::Schema 
stuff under Model::Domain and the application model under Model::App)

(b) look at how C::M::DBIC::Schema persists the $schema object, re-implement 
that and then just build your own layer for the rest

 From what you've said I suspect you'll want (b) in the long run, but (a) may 
be easier to get started with and it shouldn't be too much hassle to switch 
across later.

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list