[Dbix-class] Schema and Loader
Alan Humphrey
alan.humphrey at comcast.net
Sat Jan 7 06:35:34 CET 2006
This is what ended up working for me:
package BirdWeb::Admin::Model::BirdWebSchema;
use strict;
use base qw/DBIx::Class::Schema/;
use DBIx::Class::Loader;
my $loader = DBIx::Class::Loader->new(
dsn => 'dbi:mysql:BirdWeb',
user => 'user',
password => 'pass',
namespace =>
'BirdWeb::Admin::Model::BirdWebSchema',
relationships => 1
);
foreach my $class ( $loader->classes ) {
$class =~ s/.*::(.*)$/$1/;
__PACKAGE__->load_classes( $class );
}
1;
-----Original Message-----
From: dbix-class-bounces at lists.rawmode.org
[mailto:dbix-class-bounces at lists.rawmode.org] On Behalf Of Jason Kohles
Sent: Thursday, January 05, 2006 12:06 PM
To: dbix-class at lists.rawmode.org
Subject: Re: [Dbix-class] Schema and Loader
On 1/5/06, Alan Humphrey <alan.humphrey at comcast.net> wrote:
>
> Background: I'm updating a Catalyst app that now uses
Catalyst::Model::CDBI.
> My DB has approx 40 tables, but using the auto loading in Catalyst I can
> get away with creating modules for only a handful of the tables. I'd like
> the same ease of use using DBIx.
>
This is how I do it....
use DBIx::Class::Loader;
use UNIVERSAL::require;
# loader creates the basic classes for everything in the database
my $loader = DBIx::Class::Loader->new(
dsn => 'dbi:pg:dbname=whatever',
namespace => 'MyApp',
relationships => 1,
....
);
# then we attempt to load additional code for any of those classes, if any
foreach my $class ( $loader->classes ) {
$class->require;
}
# and restart the C3 MRO calculations, just in case any of the code we
# just loaded messed with inheritance
Class::C3::reinitialize();
--
Jason Kohles
email at jasonkohles.com - http://www.jasonkohles.com/
"A witty saying proves nothing." -- Voltaire
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
More information about the Dbix-class
mailing list