Merging patch from ddascalescu+perl@gmail.com, for https://rt.cpan.org/Ticket/Display...
Darren Chamberlain [Tue, 11 Jan 2011 16:56:22 +0000 (16:56 +0000)]
lib/SQL/Translator/Producer/SQLite.pm

index 2e7aa6a..d7d3816 100644 (file)
@@ -234,6 +234,9 @@ sub create_table
     #
     my $c_name_default = 'A';
     for my $c ( $table->get_constraints ) {
+        if ($c->type eq "FOREIGN KEY") {
+            push @field_defs, create_foreignkey($c);
+        }
         next unless $c->type eq UNIQUE; 
         push @constraint_defs, create_constraint($c);
     }
@@ -243,6 +246,15 @@ sub create_table
     return (@create, $create_table, @index_defs, @constraint_defs );
 }
 
+sub create_foreignkey {
+    my $c = shift;
+    
+    my $fk_sql = "FOREIGN KEY(".$c->{fields}[0].") REFERENCES ";
+    $fk_sql .= $c->{reference_table}."(".$c->{reference_fields}[0].")";
+    
+    return $fk_sql;
+}
+
 sub create_field
 {
     my ($field, $options) = @_;