From: Daniel Westermann-Clark Date: Wed, 12 Apr 2006 15:03:00 +0000 (+0000) Subject: Merge 'trunk' into 'DBIx-Class-current' X-Git-Tag: v0.07002~75^2~241 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=40db5831746a112e15dec9a3dbabac60e59b76b0;hp=27c1f9e933c3f3d0682c96c853af00cbbe350fe4;p=dbsrgits%2FDBIx-Class.git Merge 'trunk' into 'DBIx-Class-current' 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 --- diff --git a/Changes b/Changes index c33cc68..ea392d3 100644 --- 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 diff --git a/lib/DBIx/Class/Manual/DocMap.pod b/lib/DBIx/Class/Manual/DocMap.pod index 86a6050..507ace7 100644 --- a/lib/DBIx/Class/Manual/DocMap.pod +++ b/lib/DBIx/Class/Manual/DocMap.pod @@ -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 - Accessor grouping. - =back =head1 Retrieving and creating data @@ -61,4 +62,4 @@ =item L - Storage using L and L. -=back \ No newline at end of file +=back diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 0289c0f..3541516 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -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; } diff --git a/t/run/01core.tl b/t/run/01core.tl index 4634355..1901380 100644 --- a/t/run/01core.tl +++ b/t/run/01core.tl @@ -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