Subject: | Class::DBI::Loader::SQLite fails to set up FOREIGN KEY relations (patch included) |
The foreign key syntax is
FOREIGN KEY (local_key) REFERENCES foreign_table(foreign_key)
CDBI::L:SQLite reduces this on line 80 to '(local_key) REFERENCES ...' and tries to match it with: /^(\w+).*REFERENCES\s+(\w+)/i
Which you can see won't work on account of the braces. I think the
correct regexp should be: /^\((\w+)\).*REFERENCES\s+(\w+)/i
This for me correctly produces the right relationships
--
Lyon Lemmens
--[patch]--
@@ -77,7 +77,7 @@
$col =~ s/^\s+//gs;
# Grab reference
- if ( $col =~ /^(\w+).*REFERENCES\s+(\w+)/i ) {
+ if ( $col =~ /^\((\w+)\).*REFERENCES\s+(\w+)/i ) {
warn qq/Found foreign key definition "$col"/ if $self->debug;
eval { $self->_has_a_many( $table, $1, $2 ) };
warn qq/has_a_many failed "$@"/ if $@ && $self->debug;