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

Stephan Szabo sszabo at megazone.bigpanda.com
Mon Mar 27 05:51:04 CEST 2006


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?



More information about the Dbix-class mailing list