[Dbix-class] Using sqlt with DBIx-Class schemas

Matija Grabnar matija at literal.si
Mon May 1 13:04:47 CEST 2006

Ash Berlin wrote:
> Matija Grabnar wrote:
>> For a project (in Catalyst, if it matters) I wanted to write a 
>> DBIx::Class schema first, then use sqlt to translate that schema into 
>> appropriate SQL commands to create the database. (I considered doing it 
>> the other way, but I don't think sqlt would correctly pick up 
>> many-to-many relations automaticaly)
>> However, I'm having a problem: sqlt refuses to parse my DBIx::Class schema.
>> The error is:
>> Error: translate: Error with parser 'DBIx::Class': Undefined subroutine 
>> &DBIx::Class::parse called at 
>> /usr/local/share/perl/5.8.8/SQL/Translator.pm line 484.
>> When I run sqlt in debug mode, I see a difference between how the 
>> DBIx::Class producer (which works) and the parser (which doesn't work) 
>> get registered:
> This was a problem i discovered and I thought Matt made a note of maybe
> not. The problem is sqlt is pickup up DBIx::Class (as in the db access
> module) before it picks up SQL::Translator::Parser::DBIx::Class. Perhaps
> try the following (untested) cmd
> sqlt -d -f SQL-Translator-Parser-DBIx-Class -t DBIx-Class-File 
> STest/Schema.pm

Aha! That got me a few steps forward, but now I get:
[SQL::Translator] Got parser: code ref
[SQL::Translator] Got producer: code ref
[SQL::Translator] Got parser: SQL::Translator::Parser::DBIx::Class::parse
[SQL::Translator] Got producer: 
Error: translate: Error with parser 
'SQL::Translator::Parser::DBIx::Class': No DBIx::Schema at 
/usr/local/share/perl/5.8.8/SQL/Translator/Parser/DBIx/Class.pm line 34.

Looking at the code, I see that the parser expects to see the schema in the
    my $dbixschema  = $args->{'DBIx::Schema'} || $data;
    $dbixschema   ||= $args->{'package'};

Going through sqlt with debugger, I see args being set up, but I don't 
see any way whatsoever of passing a "DBIx::Schema" or "package" 
parameter to the parser. I must be missing something.

Is anybody using sqlt to translate DBIx::Class schemas into other stuff? 
If not, what are you using? And is, whatever you're using, able to 
specify the full range of DBIx::Class relationships, including many_to_many?

More information about the Dbix-class mailing list