sqlt parser now respected a relationship attribute of is_foreign_key_constraint
Ash Berlin [Sun, 18 Mar 2007 23:58:07 +0000 (23:58 +0000)]
Changes
lib/DBIx/Class/Relationship/Base.pm
lib/SQL/Translator/Parser/DBIx/Class.pm

diff --git a/Changes b/Changes
index 2571ace..7f41e49 100644 (file)
--- 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)
index 8409165..f31e685 100644 (file)
@@ -102,6 +102,13 @@ related object, but you also want the relationship accessor to double as
 a column accessor). For C<multi> accessors, an add_to_* method is also
 created, which calls C<create_related> for the relationship.
 
+=item is_foreign_key_constraint
+
+If you are using L<SQL::Translator> 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
index edf6224..e3f0860 100644 (file)
@@ -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',