[Catalyst] Re: Sharing a database handle between components
Matt S Trout
dbix-class at trout.me.uk
Sun Feb 10 10:19:23 GMT 2008
On Sun, Feb 10, 2008 at 09:52:21AM +0100, Aristotle Pagaltzis wrote:
> * Matt S Trout <dbix-class at trout.me.uk> [2008-02-10 08:50]:
> > To reduce coupling I'd probably do (in MyAPP)
> >
> > __PACKAGE__->config(
> > 'View::TT' => { template_db_model => 'Foo' }
> > );
> >
> > and then have the view use thatas the arg to $c->model during new.
>
> That still couples the view to a specific type of model though:
> how to get the DBH out of a DBIC::Schema model is different from
> how to do it with a DBI model, and with the approach you propose,
> that logic lives in the view class.
I'd probably have a mapping for how to do that.
Putting it in the app class is no less wrong than putting it in the view
class, really - "how do I get a dbh out of $thing" is a general concern so
some sort of adaptor/driver approach is probably best if you're trying
to keep it separated out.
Or you could just require that your models implement a get_dbh method.
Which is preferred probably depends on your codebase.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the Catalyst
mailing list