Since nobody posted any reasons why I shouldn't do this, I'm attaching a
patch for SQL::Translator::Parser::DBIx::Class which makes it possible
to have a has_many referenced from a non-primary key, as long as that
key is constrained to be unique.
I believe that this is sufficient condition for relationships to work
correctly, and in fact, I need this for a project I am working on.
Please, tell me if there is anything more I need to do to get the patch
accepted.
--- Class.pm.old 2007-01-15 12:14:32.000000000 +0100
+++ Class.pm 2007-03-24 12:20:35.000000000 +0100
@@ -121,11 +121,18 @@
}
#Decide if this is a foreign key based on whether the self
- #items are our primary columns.
+ #items are our unique columns.
# If the sets are different, then we assume it's a
foreign key
from
# us to another table.
- if (!$source->compare_relationship_keys([EMAIL PROTECTED],
[EMAIL PROTECTED])) {
+ my $has_unique=$source->
+ compare_relationship_keys([EMAIL PROTECTED], [EMAIL
PROTECTED]);
+ foreach my $uniq (keys %unique_constraints) {
+ last if $has_unique;
+ $has_unique = 1 if $source->compare_relationship_keys
+ ([EMAIL PROTECTED], $unique_constraints{$uniq});
+ }
+ if (! $has_unique) {
$table->add_constraint(
type => 'foreign_key',
name => "fk_$keys[0]",
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/