[Bast-commits] r9437 - in DBIx-Class/0.08/branches/extended_rels: lib/DBIx/Class t/lib/DBICTest/Schema t/relationship

ruoso at dev.catalyst.perl.org ruoso at dev.catalyst.perl.org
Tue May 25 18:50:55 GMT 2010


Author: ruoso
Date: 2010-05-25 19:50:55 +0100 (Tue, 25 May 2010)
New Revision: 9437

Modified:
   DBIx-Class/0.08/branches/extended_rels/lib/DBIx/Class/ResultSource.pm
   DBIx-Class/0.08/branches/extended_rels/lib/DBIx/Class/SQLAHacks.pm
   DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Artist.pm
   DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Track.pm
   DBIx-Class/0.08/branches/extended_rels/t/relationship/custom.t
Log:
[extended-rels] First attempt to make extended_rels work.

Modified: DBIx-Class/0.08/branches/extended_rels/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/lib/DBIx/Class/ResultSource.pm	2010-05-25 18:32:39 UTC (rev 9436)
+++ DBIx-Class/0.08/branches/extended_rels/lib/DBIx/Class/ResultSource.pm	2010-05-25 18:50:55 UTC (rev 9437)
@@ -1290,7 +1290,7 @@
                -alias => $as,
                -relation_chain_depth => $seen->{-relation_chain_depth} || 0,
              },
-             $self->_resolve_condition($rel_info->{cond}, $as, $alias) ];
+             $self->_resolve_condition($rel_info->{cond}, $as, $alias, $join) ];
   }
 }
 
@@ -1348,8 +1348,31 @@
 our $UNRESOLVABLE_CONDITION = \'1 = 0';
 
 sub _resolve_condition {
-  my ($self, $cond, $as, $for) = @_;
-  if (ref $cond eq 'HASH') {
+  my ($self, $cond, $as, $for, $rel) = @_;
+  if (ref $cond eq 'CODE') {
+
+    # heuristic for the actual relname
+    if (! defined $rel) {
+      if (!ref $as) {
+        $rel = $as;
+      }
+      elsif (!ref $for) {
+        $rel = $for;
+      }
+    }
+
+    if (! defined $rel) {
+      $self->throw_exception ('Unable to determine relationship name for condition resolution');
+    }
+
+    $cond = $cond->(
+      $for,
+      ref $for ? 'me' : $as,
+      $self,
+      $rel,
+    );
+
+  } elsif (ref $cond eq 'HASH') {
     my %ret;
     foreach my $k (keys %{$cond}) {
       my $v = $cond->{$k};
@@ -1393,7 +1416,7 @@
   } elsif (ref $cond eq 'ARRAY') {
     return [ map { $self->_resolve_condition($_, $as, $for) } @$cond ];
   } else {
-   die("Can't handle condition $cond yet :(");
+    $self->throw_exception ("Can't handle condition $cond yet :(");
   }
 }
 

Modified: DBIx-Class/0.08/branches/extended_rels/lib/DBIx/Class/SQLAHacks.pm
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/lib/DBIx/Class/SQLAHacks.pm	2010-05-25 18:32:39 UTC (rev 9436)
+++ DBIx-Class/0.08/branches/extended_rels/lib/DBIx/Class/SQLAHacks.pm	2010-05-25 18:50:55 UTC (rev 9437)
@@ -576,8 +576,8 @@
     for (keys %$cond) {
       my $v = $cond->{$_};
       if (ref $v) {
-        croak (ref($v) . qq{ reference arguments are not supported in JOINS - try using \"..." instead'})
-            if ref($v) ne 'SCALAR';
+        #croak (ref($v) . qq{ reference arguments are not supported in JOINS - try using \"..." instead'})
+        #    if ref($v) ne 'SCALAR';
         $j{$_} = $v;
       }
       else {

Modified: DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Artist.pm
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Artist.pm	2010-05-25 18:32:39 UTC (rev 9436)
+++ DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Artist.pm	2010-05-25 18:50:55 UTC (rev 9437)
@@ -46,12 +46,12 @@
 __PACKAGE__->has_many(
     cds_80s => 'DBICTest::Schema::CD',
     sub {
-        my ( $self_alias, $rel_alias, $self_rsrc, $rel_name ) = @_;
-        return {
-            "${rel_alias}.artist" => \ "${self_alias}.artistid",
-            "${rel_alias}.year"   => { '>', "1979" },
-            "${rel_alias}.year"   => { '<', "1990" }
-        };
+      my ( $me, $as, $self_rsrc, $rel ) = @_;
+      return {
+        "${as}.artist" => (ref $me ? $me->artistid : { '=' => \"${me}.artistid"}),
+        "${as}.year"   => { '>', "1979",
+                            '<', "1990" }
+      };
     }
 );
 

Modified: DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Track.pm
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Track.pm	2010-05-25 18:32:39 UTC (rev 9436)
+++ DBIx-Class/0.08/branches/extended_rels/t/lib/DBICTest/Schema/Track.pm	2010-05-25 18:50:55 UTC (rev 9437)
@@ -67,10 +67,10 @@
     'next_track',
     __PACKAGE__,
     sub {
-        my ( $self_alias, $rel_alias, $self_rsrc, $rel_name ) = @_;
+        my ( $me, $as, $self_rsrc, $rel_name ) = @_;
         return {
-            "${self_alias}.cd" => \ "${rel_alias}.cd",
-            "${self_alias}.position" => { '<', \ "${rel_alias}.position" },
+            "${as}.cd" => (ref $me ? $me->cd : { '=' => \"${me}.cd" }),
+            "${as}.position" => { '>', (ref $me ? $me->position : \"${me}.position" )},
         };
     },
 );

Modified: DBIx-Class/0.08/branches/extended_rels/t/relationship/custom.t
===================================================================
--- DBIx-Class/0.08/branches/extended_rels/t/relationship/custom.t	2010-05-25 18:32:39 UTC (rev 9436)
+++ DBIx-Class/0.08/branches/extended_rels/t/relationship/custom.t	2010-05-25 18:50:55 UTC (rev 9437)
@@ -10,6 +10,7 @@
 
 
 my $artist = $schema->resultset("Artist")->create({ name => 'Michael Jackson' });
+
 foreach my $year (1975..1985) {
   $artist->create_related('cds', { year => $year, title => 'Compilation from ' . $year });
 }
@@ -38,7 +39,7 @@
 
 is_deeply (
   [$last_tracks->get_column ('trackid')->all],
-  \@last_track_ids,
+  [ grep { $_ } @last_track_ids ],
   'last group-entry via self-join works',
 );
 




More information about the Bast-commits mailing list