[Dbix-class] SQL::Translator::Parser::DBIx::Class

Matt S Trout dbix-class at trout.me.uk
Mon Mar 27 15:03:01 CEST 2006


Stephan Szabo wrote:
> On Sun, 26 Mar 2006, Stephan Szabo wrote:
> 
>> While playing with SQL::Translator to generate sql scripts from schemas, I
>> noticed that the DBIx::Class parser seemed to grab only one column of
>> multi-column relationships. It looks like just making it work across
>> $rel_info->{cond} into an array rather than taking only the first key
>> should work, something like:
>>
>> my @cond = keys(%{$rel_info->{cond}});
>> my @keys = map {/^\w+\.(\w+)$/} @cond;
>> my @refkeys = map {$rel_info->{cond}->{$_} =~ /^\w+\.(\w+)$/} @cond;
> 
> And I should really actually cut and paste rather than doing it freehand
> when I copy something into an email and/or check it before sending. The
> above assignments are backwards (it should be refkeys in the first and
> keys in the second).
> 
>> if($rel_table)
>> {
>>     $table->add_constraint(
>>                 type             => 'foreign_key',
>>                 name             => "fk_$keys[0]",
>>                 fields           => \@keys,
>>                 reference_fields => \@refkeys,
>>                 reference_table  => $rel_table,
>>     );
>> }
>>
>> Does that seem reasonable?

Seems like a damn good start to me. If you grab svn and apply that tweak then
get maint/gen-schema.pl to load the HelperRels stuff so it's got some 
relationships to work with and see what the SQLite file you end up with looks 
like?

Also note the bigass comment I left just above that section about what needs 
to produce an FK constraint and what doesn't :)

(I'd apply this and clear it up myself but I don't think I'll have time next 
couple days, sorry - so have a play and tell the list how far you get and 
we'll see what we can do ...)

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list