[Dbix-class] CDBICompat

Dave Howorth dhoworth at mrc-lmb.cam.ac.uk
Fri Nov 7 17:17:00 GMT 2008


Dave Howorth wrote:
 > I've poked around a bit but can't see where schema is set up.

I've poked around some more and think I've found the source of the
problem. I went back to a small example that worked and then
experimented until it broke. Here's the guts (all one file):


#!/usr/bin/perl
use strict;
use warnings;

package Music::DBI;

use base 'Class::DBI';
#use base 'DBIx::Class::CDBICompat';

#Music::DBI->connection('dbi:mysql:test', 'dave', '');


package Music::Artist;
use base 'Music::DBI';
Music::Artist->table('artist', 'artist');
Music::Artist->columns(All => qw/artistid name popularity/);


package Music::CD;
use base 'Music::DBI';
Music::CD->table('cd', 'cd');
Music::CD->columns(All => qw/cdid artistid title publishdate/);


package my;

Music::DBI->connection('dbi:mysql:test', 'dave', 'password');

my $artist = Music::Artist->find_or_create({
        name        => 'Beatles, the',
        popularity  => 99,
        });


That code works. If I switch to:

#use base 'Class::DBI';
use base 'DBIx::Class::CDBICompat';

it doesn't work. If I switch the position of the call to connection() it
works again. Unfortunately, that's not easy to do in my real application.

Any thoughts on how to fix this?  Some extra magic to call at the same
time the connection is established, perhaps?

Thanks, Dave



More information about the DBIx-Class mailing list