From: Ash Berlin Date: Sun, 18 Mar 2007 23:58:07 +0000 (+0000) Subject: sqlt parser now respected a relationship attribute of is_foreign_key_constraint X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3d618782661512ffb7b263a222e183808170b88a;p=dbsrgits%2FDBIx-Class-Historic.git sqlt parser now respected a relationship attribute of is_foreign_key_constraint --- diff --git a/Changes b/Changes index 2571ace..7f41e49 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for DBIx::Class - select et al weren't properly detecing when the server connection had timed out when not in a transaction + - The SQL::T parser class now respects a relationship attribute of + is_foreign_key_constrain to allow explicit control over wether or not + a foreign constraint is needed 0.07999_02 2007-01-25 20:11:00 - add support for binding BYTEA and similar parameters (w/Pg impl) diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 8409165..f31e685 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -102,6 +102,13 @@ related object, but you also want the relationship accessor to double as a column accessor). For C accessors, an add_to_* method is also created, which calls C for the relationship. +=item is_foreign_key_constraint + +If you are using L to create SQL for you and you find that it +is creating constraints where it shouldn't, or not creating them where it +should, set this attribute to a true or false value to override the detection +of when to create constraints. + =back =head2 register_relationship diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index edf6224..e3f0860 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -145,16 +145,18 @@ sub parse { #Decide if this is a foreign key based on whether the self #items are our primary columns. + $DB::single = 1 if $moniker eq 'Tests::MBTI::Result'; # If the sets are different, then we assume it's a foreign key from # us to another table. - # OR: If is_foreign_key attr is explicity set on one the local columns - if ( ! exists $created_FK_rels{$rel_table}->{$key_test} - && - ( !$source->compare_relationship_keys(\@keys, \@primary) || - grep { $source->column_info($_)->{is_foreign_key} } @keys - ) - ) { + # 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} || + !$source->compare_relationship_keys(\@keys, \@primary) + ) + ) + { $created_FK_rels{$rel_table}->{$key_test} = 1; $table->add_constraint( type => 'foreign_key',