[Dbix-class] Schema and Loader

Jason Kohles email at jasonkohles.com
Thu Jan 5 21:05:52 CET 2006


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



More information about the Dbix-class mailing list