From: Ash Berlin Date: Tue, 25 Sep 2007 15:39:52 +0000 (+0000) Subject: Throw if "foreign." and "self." are wrong way round in conditions for relationships X-Git-Tag: v0.08010~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eba322a7c38a91bfc974faeaed86c638d2cedff9;p=dbsrgits%2FDBIx-Class.git Throw if "foreign." and "self." are wrong way round in conditions for relationships --- diff --git a/Changes b/Changes index ccb5ded..85ccfb8 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for DBIx::Class + - When adding relationships, it will throw an exception if you get the + foreign and self parts the wrong way round in the condition + 0.08007 2007-09-04 19:36:00 - patch for Oracle datetime inflation (abram@arin.net) - added on_disconnect_do diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index d21cdb7..70ec967 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -519,6 +519,14 @@ sub add_relationship { unless $cond; $attrs ||= {}; + # Check foreign and self are right in cond + if ( (ref $cond ||'') eq 'HASH') { + for (keys %$cond) { + $self->throw_exception("Keys of condition should be of form 'foreign.col', not '$_'") + if /\./ && !/^foreign\./; + } + } + my %rels = %{ $self->_relationships }; $rels{$rel} = { class => $f_source_name, source => $f_source_name, diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index e3f0860..1f09482 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -128,7 +128,6 @@ sub parse { if($rel_table) { - my $reverse_rels = $source->reverse_relationship_info($rel); my ($otherrelname, $otherrelationship) = each %{$reverse_rels}; @@ -145,7 +144,6 @@ 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.