[Dbix-class] Extending a schema after instanciating it

Matt S Trout dbix-class at trout.me.uk
Mon Aug 18 11:04:09 BST 2008


On Sun, Aug 17, 2008 at 08:43:23PM +0200, Guillaume Rousse wrote:
> Hello list.
> 
> I'm facing a strange problem with DBIx::Class. Due to the nature of my 
> application (run-time discovery of configured plugins, each extending 
> the basic schema), I need to load and deploy the schema class by class, 
> after creating the schema. However, the following code does not work:
> 
> #!/usr/bin/perl
> use strict;
> use My::Schema;
> use Data::Dumper;
> my $schema = My::Schema->connect('dbi:SQLite:/home/guillaume/my.db');
> 
> print Dumper($schema->sources());
> My::Schema->load_classes('Other');
> print Dumper($schema->sources());
> 
> The 'Other' class is not registered.

Correct. As the documentation states, ->connect is a shortcut for ->clone
and ->connection. Once you clone the schema the sources list is now
separate so doing things to original won't change anything.

Either (a) do a register_class by hand or (b) do

my $new_schema = My::Schema->clone;
$new_schema->storage($old_schema->storage);

and use $new_schema from then on (or at least utnil you need to modify
My::Schema again)

-- 
      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 DBIx-Class mailing list