[Dbix-class] Catalyst::Model::DBIC::Schema patch for overloading connection.
Brandon Black
blblack at gmail.com
Mon May 1 16:52:28 CEST 2006
On 5/1/06, Jesper Krogh <jesper at krogh.cc> wrote:
> Hi.
>
> This patch makes it possible to overload ->connection in the specific
> model class. This used for example when using the TypeBasedInflation stuff
> from the wiki.
>
The patch as you're doing it makes a connection in the
composed_schema, rather than in the derived schema.
In DBIx::Class::Schema, ->connection sets up a connection on whatever
schema class/object it was called on, while ->connect clones whatever
it was called on, then calls ->connection on that new object and
returns it.
The intent with the model was that ->composed_schema be an unconnected
object, and ->schema be the connected schema object (although IIRC
there's also some magic going on where the model itself also acts as
the composed_schema, but our ->schema accessor conveniently makes
certain things work correctly for that).
There's probably another way to patch the Model to allow an overriden
"connection" there to work, without connecting the composed_schema,
I'm just not sure what that is at the moment ...
The cleanest approach, IMHO, would probably be to subclass your
DBIx::Class::Schema class and override the connection() method there,
and then use it as normal in the model class:
package MyApp::Schema;
... normal schema setup ...
package MyApp::SchemaForTheWeb;
use base qw/MyApp::Schema/;
sub connection {
... override as per wiki, roughly ...
}
package MyApp::Model::WebSchema;
__PACKAGE__->config(
schema_class => 'MyApp::SchemaForTheWeb';
);
More information about the Dbix-class
mailing list