Jon Schutz wrote:
> I've added is_foreign_key_constraint => 0 as an attribute in a
> relationship, in order to query across the join without imposing
> database level constraints - but the constraint is still appearing in
> the resulting schema.
> 
> The doco in Relationship::Base says "set this attribute to a true or
> false value to override the detection of when to create constraints."
> 
> Can anyone (particular Jess & Matt whose

Except I wrote that bit of code ;)

 names can be found in the
> source) explain the logic in the following bit of code to me?  From
> SQL::Translator::Parser::DBIx::Class.pm :
> 
>                # Make sure we dont create the same foreign key constraint 
> twice
>                 # Decide if this is a foreign key based on whether the self
>                 # items are our primary columns.
>                 # If the sets are different, then we assume it's a foreign 
> key from
>                 # 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} ||
>                        !$source->compare_relationship_keys([EMAIL PROTECTED], 
> [EMAIL PROTECTED])
>                      )
>                    )
>                 {
>                     $created_FK_rels{$rel_table}->{$key_test} = 1;
>                     $table->add_constraint(
>                                ...
>                     );
>                 }
> 
> I read it as - if the foreign key has already been created, don't try to
> recreate the same one.  If is_foreign_key_constraint has been specified
> and is set, or if the keys are not primary keys, then create the foreign
> key relation.  So it seems we can force foreign keys with
> is_foreign_key_constraint = true, but can't forcibly disable them as the
> compare_relationship_keys test wins in the end.
> 
> Shouldn't that logic be : if is_foreign_key_constraint has been
> specified then do whatever it says, otherwise test using
> compare_relationship_keys ? i.e.
> 
>                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([EMAIL PROTECTED], 
> [EMAIL PROTECTED]) 
>                    ) 
>                  ) ...
>  
> ?
> 

Yes good point. Of course I only ever wanted it to force creating of
keys, not stop it. Fancy putting together some test cases for this? (By
creating a patch against t/86sqlt.t and other files?

-ash

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to