Renamed DBIx::Class::PK's retrieve() as find()
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / Relationship.pm
index 87f8f11..14741b0 100644 (file)
@@ -104,6 +104,18 @@ sub _cond_value {
 
 sub search_related {
   my $self = shift;
+  return $self->_literal_related('search', @_);
+}
+
+sub count_related {
+  my $self = shift;
+  return $self->_literal_related('count', @_);
+}
+
+sub _literal_related {
+  my $self = shift;
+  my $op = shift;
+  my $meth = "${op}_literal";
   my $rel = shift;
   my $attrs = { };
   if (@_ > 1 && ref $_[$#_] eq 'HASH') {
@@ -118,11 +130,12 @@ sub search_related {
     my $query = ((@_ > 1) ? {@_} : shift);
     $s_cond = $self->_cond_resolve($query, $attrs);
   }
-  $attrs->{_action} = 'convert';
+  $attrs->{_action} = 'convert'; # shouldn't we resolve the cond to something
+                                 # to merge into the AST really?
   my ($cond) = $self->_cond_resolve($rel_obj->{cond}, $attrs);
   $cond = "${s_cond} AND ${cond}" if $s_cond;
-  return $rel_obj->{class}->retrieve_from_sql($cond, @{$attrs->{bind} || []},
-                                                $attrs);
+  #warn $rel_obj->{class}." $meth $cond ".join(', ', @{$attrs->{bind}});
+  return $rel_obj->{class}->$meth($cond, @{$attrs->{bind} || []}, $attrs);
 }
 
 sub create_related {
@@ -182,22 +195,6 @@ sub update_from_related {
   $self->update;
 }
 
-sub count_related {
-  my $self = shift;
-  my $rel = shift;
-  my $rel_obj = $self->_relationships->{$rel};
-  $self->throw( "No such relationship ${rel}" ) unless $rel_obj;
-  my $cond = $rel_obj->{cond};
-  my $count_cond = {};
-  foreach my $key (keys %$cond) {
-    $key =~ m/^foreign\.([^\.]+)$/;
-    my $count_key = $1;
-    $cond->{$key} =~ m/^self\.([^\.]+)$/;
-    $count_cond->{$count_key} = $self->get_column($1);
-  }
-  return $rel_obj->{class}->count( $count_cond );
-}
-
 1;
 
 =back