Subject: | Multiple field foreign keys in SQL::Translator::Producer::Diagram |
The Diagram output from sqlt is currently confusing where a compound
foreign key is represented, as it shows more links than necessary -
between all of the fields involved in the foreign key.
This is down to the double looping of the local->foreign key (Lines
268-276).
I have attached a patch that fixes this by linking each local field to
foreign field in turn.
Sadly, I cannot work out how to test this automatically as I don't
understand how to test the produced image for correctness.
Subject: | SQL-Translator-Producer-Diagram.patch |
--- Diagram.0.11011.pm 2012-06-25 08:16:23.441080883 +0100
+++ Diagram.0.11011.pm.patched 2012-06-25 08:26:35.541280677 +0100
@@ -264,15 +264,16 @@
for my $c ( $table->get_constraints ) {
next unless $c->type eq FOREIGN_KEY;
my $fk_table = $c->reference_table or next;
+ next unless defined $schema->get_table( $fk_table );
- for my $field_name ( $c->fields ) {
- for my $fk_field ( $c->reference_fields ) {
- next unless defined $schema->get_table( $fk_table );
- push @fk_registry, [
- [ $fk_table , $fk_field ],
- [ $table_name, $field_name ],
- ];
- }
+ my @local_fields = $c->fields;
+ my @foreign_fields = $c->reference_fields;
+
+ for ( my $i = 0; $i < scalar( @local_fields ); $i++ ) {
+ push @fk_registry, [
+ [ $fk_table , $foreign_fields[$i] ],
+ [ $table_name, $local_fields[$i] ],
+ ];
}
}
}