Merge 'trunk' into 'DBIx-Class-current'
Daniel Westermann-Clark [Wed, 12 Apr 2006 15:03:00 +0000 (15:03 +0000)]
r8443@fortuna (orig r1442):  dwc | 2006-04-11 23:29:12 -0400
POD fix for search.cpan.org
r8446@fortuna (orig r1443):  dwc | 2006-04-12 11:01:57 -0400
Fix for -and conditions when updating or deleting on a ResultSet

Changes
lib/DBIx/Class/Manual/DocMap.pod
lib/DBIx/Class/ResultSet.pm
t/run/01core.tl

diff --git a/Changes b/Changes
index c33cc68..ea392d3 100644 (file)
--- a/Changes
+++ b/Changes
@@ -5,6 +5,9 @@ Revision history for DBIx::Class
         - added source_name to ResultSource
        - load_classes now uses source_name and sets it if necessary
 
+0.06002
+        - fix for -and conditions when updating or deleting on a ResultSet
+
 0.06001
         - minor fix to update in case of undefined rels
         - fixes for cascade delete
index 86a6050..507ace7 100644 (file)
@@ -1,4 +1,6 @@
-=head1 NAME DBIx::Class::Manual::DocMap - What documentation do we have?
+=head1 NAME
+
+DBIx::Class::Manual::DocMap - What documentation do we have?
 
 =head1 Manuals
 
@@ -46,7 +48,6 @@
 
 =item L<DBIx::Class::AccessorGroup> - Accessor grouping.
 
-
 =back
 
 =head1 Retrieving and creating data
@@ -61,4 +62,4 @@
 
 =item L<DBIx::Class::Storage::DBI> - Storage using L<DBI> and L<SQL::Abstract>.
 
-=back
\ No newline at end of file
+=back
index 0289c0f..3541516 100644 (file)
@@ -810,14 +810,14 @@ sub first {
 #
 # update/delete require the condition to be modified to handle
 # the differing SQL syntax available.  This transforms the $self->{cond}
-# appropriately, returning the new condition
+# appropriately, returning the new condition.
 
 sub _cond_for_update_delete {
   my ($self) = @_;
   my $cond = {};
 
   if (!ref($self->{cond})) {
-    # No-op. No condition, we're update/deleting everything
+    # No-op. No condition, we're updating/deleting everything
   }
   elsif (ref $self->{cond} eq 'ARRAY') {
     $cond = [
@@ -828,21 +828,31 @@ sub _cond_for_update_delete {
           $hash{$1} = $_->{$key};
         }
         \%hash;
-        } @{$self->{cond}}
+      } @{$self->{cond}}
     ];
   }
   elsif (ref $self->{cond} eq 'HASH') {
     if ((keys %{$self->{cond}})[0] eq '-and') {
-      $cond->{-and} = [
-        map {
-          my %hash;
-          foreach my $key (keys %{$_}) {
+      $cond->{-and} = [];
+
+      my @cond = @{$self->{cond}{-and}};
+      for (my $i = 0; $i < @cond - 1; $i++) {
+        my $entry = $cond[$i];
+
+        my %hash;
+        if (ref $entry eq 'HASH') {
+          foreach my $key (keys %{$entry}) {
             $key =~ /([^.]+)$/;
-            $hash{$1} = $_->{$key};
+            $hash{$1} = $entry->{$key};
           }
-          \%hash;
-          } @{$self->{cond}{-and}}
-      ];
+        }
+        else {
+          $entry =~ /([^.]+)$/;
+          $hash{$entry} = $cond[++$i];
+        }
+
+        push @{$cond->{-and}}, \%hash;
+      }
     }
     else {
       foreach my $key (keys %{$self->{cond}}) {
@@ -853,8 +863,10 @@ sub _cond_for_update_delete {
   }
   else {
     $self->throw_exception(
-               "Can't update/delete on resultset with condition unless hash or array");
+      "Can't update/delete on resultset with condition unless hash or array"
+    );
   }
+
   return $cond;
 }
 
index 4634355..1901380 100644 (file)
@@ -1,7 +1,7 @@
 sub run_tests {
 my $schema = shift;
 
-plan tests => 49;
+plan tests => 51;
 
 # figure out if we've got a version of sqlite that is older than 3.2.6, in
 # which case COUNT(DISTINCT()) doesn't work
@@ -181,6 +181,25 @@ cmp_ok($tag->has_column_loaded('tag'), '==', 0, 'Has not tag  loaded');
 
 ok($schema->storage(), 'Storage available');
 
+{
+  my $rs = $schema->resultset("Artist")->search({
+    -and => [
+      artistid => { '>=', 1 },
+      artistid => { '<', 3 }
+    ]
+  });
+
+  $rs->update({ name => 'Test _cond_for_update_delete' });
+
+  my $art;
+
+  $art = $schema->resultset("Artist")->find(1);
+  is($art->name, 'Test _cond_for_update_delete', 'updated first artist name');
+
+  $art = $schema->resultset("Artist")->find(2);
+  is($art->name, 'Test _cond_for_update_delete', 'updated second artist name');
+}
+
 # test source_name
 {
   # source_name should be set for normal modules