From: Ash Berlin Date: Thu, 15 Nov 2007 12:49:53 +0000 (+0000) Subject: Fix is_foreign_key_constraint - thanks Jon Schutz X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a0024650c5dfd609c73a3ec954ba13c67870af3f;p=dbsrgits%2FDBIx-Class-Historic.git Fix is_foreign_key_constraint - thanks Jon Schutz --- diff --git a/lib/DBIx/Class/Storage/Statistics.pm b/lib/DBIx/Class/Storage/Statistics.pm index e94203e..c2a2209 100644 --- a/lib/DBIx/Class/Storage/Statistics.pm +++ b/lib/DBIx/Class/Storage/Statistics.pm @@ -3,6 +3,7 @@ use strict; use warnings; use base qw/Class::Accessor::Grouped/; +use IO::File; __PACKAGE__->mk_group_accessors(simple => qw/callback debugfh/); diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 58d2be9..262047b 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -149,10 +149,10 @@ sub parse { # us to another table. # OR: If is_foreign_key_constraint attr is explicity set (or set to false) on the relation if ( ! exists $created_FK_rels{$rel_table}->{$key_test} && - ( exists $rel_info->{attrs}{is_foreign_key_constraint} && - $rel_info->{attrs}{is_foreign_key_constraint} || + ( exists $rel_info->{attrs}{is_foreign_key_constraint} ? + $rel_info->{attrs}{is_foreign_key_constraint} : !$source->compare_relationship_keys(\@keys, \@primary) - ) + ) ) { $created_FK_rels{$rel_table}->{$key_test} = 1; diff --git a/t/86sqlt.t b/t/86sqlt.t index 0d3a759..ad9c480 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -10,7 +10,7 @@ plan skip_all => 'SQL::Translator required' if $@; my $schema = DBICTest->init_schema; -plan tests => 56; +plan tests => 60; my $translator = SQL::Translator->new( parser_args => { @@ -176,6 +176,16 @@ my %fk_constraints = ( on_delete => '', on_update => '', }, ], + # ForceForeign + forceforeign => [ + { + 'display' => 'forceforeign->artist', + 'selftable' => 'forceforeign', 'foreigntable' => 'artist', + 'selfcols' => ['artist'], 'foreigncols' => ['artist_id'], + on_delete => '', on_update => '', + }, + ], + ); my %unique_constraints = ( @@ -222,7 +232,6 @@ my %indexes = ( ); my $tschema = $translator->schema(); - # Test that the $schema->sqlt_deploy_hook was called okay and that it removed # the 'link' table ok( !defined($tschema->get_table('link')), "Link table was removed by hook"); @@ -232,6 +241,8 @@ my $constraint = get_constraint('FOREIGN KEY', 'cd', ['title'], 'cd', ['year']); ok( !defined($constraint), 'nonexistent FOREIGN KEY constraint not found' ); $constraint = get_constraint('UNIQUE', 'cd', ['artist']); ok( !defined($constraint), 'nonexistent UNIQUE constraint not found' ); +$constraint = get_constraint('FOREIGN KEY', 'forceforeign', ['cd'], 'cd', ['cdid']); +ok( !defined($constraint), 'forced nonexistent FOREIGN KEY constraint not found' ); for my $expected_constraints (keys %fk_constraints) { for my $expected_constraint (@{ $fk_constraints{$expected_constraints} }) { diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index 979cf84..1681cf5 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -36,7 +36,8 @@ __PACKAGE__->load_classes(qw/ ), qw/SelfRefAlias TreeLike TwoKeyTreeLike Event EventTZ NoPrimaryKey/, qw/Collection CollectionObject TypedObject/, - qw/Owners BooksInLibrary/ + qw/Owners BooksInLibrary/, + qw/ForceForeign/ ); sub sqlt_deploy_hook {