[Dbix-class] inflate_column and sql_maker->quote_char/name_sep
Brandon Black
blblack at gmail.com
Thu Mar 2 21:38:07 CET 2006
On 3/2/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
> On Thu, Mar 02, 2006 at 09:19:42PM +0100, Bernhard Graf wrote:
> > Matt S Trout wrote:
> > > On Thu, Mar 02, 2006 at 08:17:33PM +0100, Bernhard Graf wrote:
> > > > Matt S Trout wrote:
> > > > > > use base 'DBIx::Class::Schema';
> > > > > > __PACKAGE__->load_classes;
> > > > > > __PACKAGE__->storage->sql_maker->quote_char('`');
> > > > > > __PACKAGE__->storage->sql_maker->name_sep('.');
> > > > > >
> > > > > > ?
> > > > > >
> > > > > > This gives me:
> > > > > >
> > > > > > Can't call method "sql_maker" on an undefined value at
> > > > > > TDW/Schema.pm line 10. Compilation failed in require at app.pl
> > > > > > line 6.
> > > > > > BEGIN failed--compilation aborted at app.pl line 6.
> > > > >
> > > > > Ah. Storage isn't initialised unril you call connect/connection,
> > > > > as noted in the DBIx::Class::Schema docs. Should have mentioned
> > > > > that, sorry.
> > > >
> > > > I'm really confused now.
> > > > What do you mean with "isn't initialised"? Undefined?
> > > >
> > > > Does that mean, that in my application code I have to call
> > > > my $schema = CLASS->connect()
> > > > first and then
> > > > $schema->storage->sql_maker->quote_char('`');
> > > > $schema->storage->sql_maker->name_sep('.');
> > >
> > > Right.
> > >
> > > > What about $schema->storage->on_connect_do() then?
> > > > Looks like a hen-egg problem...
> > >
> > > ->connect connects the schema to the storage object. The storage
> > > object doesn't spawn a dbh until it needs one.
> >
> > To sum it up:
> >
> > my $schema = My::Schema->connect(...);
> > $schema->storage->on_connect_do(...);
> > $schema->storage->sql_maker->quote_char('`');
> > $schema->storage->sql_maker->name_sep('.');
> >
> > is the recommended approach?
>
> That should work fine. It should be fairly trivial to overload new() in
> Catalyst::Model::DBIC::Schema to do this for you automatically as well.
>
Yeah, something along the lines of:
package My::Model::Thingy;
use base qw/Catalyst::Model::DBIC::Schema/;
sub new {
my $self = shift->NEXT::new(@_);
$self->schema->storage->on_connect_do(...);
$self->schema->storage->sql_maker->quote_char(...);
$self->schema->storage->sql_maker->name_sep(...);
$self;
}
1;
(and then however you normall get your ->config values into there for
schema class and connection details).
-- Brandon
More information about the Dbix-class
mailing list