From: Arthur Axel 'fREW' Schmidt Date: Tue, 15 May 2012 13:54:24 +0000 (-0500) Subject: Add flag for correctly introspecting fk rels X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1cc9d17ba6b1b3fce6ee42177ab80992341b8b11;p=dbsrgits%2FDBIx-Class.git Add flag for correctly introspecting fk rels --- diff --git a/Changes b/Changes index 2fef676..2c5465a 100644 --- a/Changes +++ b/Changes @@ -34,6 +34,7 @@ Revision history for DBIx::Class - Transaction support - Support for VARCHAR(MAX)/VARBINARY(MAX)/NVARCHAR(MAX) datatypes - Nomalization of retrieved GUID values + - Added flag for correctly introspecting foreign key relationships * Fixes - Fix complex has_many prefetch with resultsets not selecting identity diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 6cfe28c..693ebae 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -309,6 +309,15 @@ 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_rel + +This is automatically set for all of the relationship helper methods. This is +basically a flag that allows us to correctly introspect true foreign keys; +or to be clear, this flag says "this relationship includes columns that point +to another table." +Do not confuse this with L which serves a different +purpose. + =item is_foreign_key_constraint If you are using L to create SQL for you and you find that it diff --git a/lib/DBIx/Class/Relationship/BelongsTo.pm b/lib/DBIx/Class/Relationship/BelongsTo.pm index 76ffb50..aeb434b 100644 --- a/lib/DBIx/Class/Relationship/BelongsTo.pm +++ b/lib/DBIx/Class/Relationship/BelongsTo.pm @@ -20,6 +20,9 @@ sub belongs_to { # assume a foreign key contraint unless defined otherwise $attrs->{is_foreign_key_constraint} = 1 if not exists $attrs->{is_foreign_key_constraint}; + + $attrs->{is_foreign_rel} = 1 + if not exists $attrs->{is_foreign_rel}; $attrs->{undef_on_null_fk} = 1 if not exists $attrs->{undef_on_null_fk}; diff --git a/lib/DBIx/Class/Relationship/HasMany.pm b/lib/DBIx/Class/Relationship/HasMany.pm index b8a9b4c..06a3bc3 100644 --- a/lib/DBIx/Class/Relationship/HasMany.pm +++ b/lib/DBIx/Class/Relationship/HasMany.pm @@ -51,6 +51,9 @@ sub has_many { my $default_cascade = ref $cond eq 'CODE' ? 0 : 1; + $attrs->{is_foreign_rel} = 0 + if not exists $attrs->{is_foreign_rel}; + $class->add_relationship($rel, $f_class, $cond, { accessor => 'multi', join_type => 'LEFT', diff --git a/lib/DBIx/Class/Relationship/HasOne.pm b/lib/DBIx/Class/Relationship/HasOne.pm index f9046ca..b0d21aa 100644 --- a/lib/DBIx/Class/Relationship/HasOne.pm +++ b/lib/DBIx/Class/Relationship/HasOne.pm @@ -53,6 +53,9 @@ sub _has_one { my $default_cascade = ref $cond eq 'CODE' ? 0 : 1; + $attrs->{is_foreign_rel} = 0 + if not exists $attrs->{is_foreign_rel}; + $class->add_relationship($rel, $f_class, $cond, { accessor => 'single',