X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=08e81b59ad62631ef6b96ffaea89928468461e73;hb=b044b5d3118a1a147351cb337a49f788adc7e3be;hp=857dfca9983bbe751bded17f6ad6b520bbe13508;hpb=ea1eaf8db1d8ad46a7342e45358f4bcfd293de93;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 857dfca..08e81b5 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -464,12 +464,13 @@ three records, call: sub slice { my ($self, $min, $max) = @_; - my $attrs = { %{ $self->{attrs} || {} } }; - $attrs->{offset} ||= 0; + my $attrs = {}; # = { %{ $self->{attrs} || {} } }; + $attrs->{offset} = $self->{attrs}{offset} || 0; $attrs->{offset} += $min; $attrs->{rows} = ($max ? ($max - $min + 1) : 1); - my $slice = (ref $self)->new($self->result_source, $attrs); - return (wantarray ? $slice->all : $slice); + return $self->search(undef(), $attrs); + #my $slice = (ref $self)->new($self->result_source, $attrs); + #return (wantarray ? $slice->all : $slice); } =head2 next @@ -782,6 +783,59 @@ sub first { return $_[0]->reset->next; } +# _cond_for_update_delete +# +# 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 + +sub _cond_for_update_delete { + my ($self) = @_; + my $cond = {}; + + if (!ref($self->{cond})) { + # No-op. No condition, we're update/deleting everything + } + elsif (ref $self->{cond} eq 'ARRAY') { + $cond = [ + map { + my %hash; + foreach my $key (keys %{$_}) { + $key =~ /([^.]+)$/; + $hash{$1} = $_->{$key}; + } + \%hash; + } @{$self->{cond}} + ]; + } + elsif (ref $self->{cond} eq 'HASH') { + if ((keys %{$self->{cond}})[0] eq '-and') { + $cond->{-and} = [ + map { + my %hash; + foreach my $key (keys %{$_}) { + $key =~ /([^.]+)$/; + $hash{$1} = $_->{$key}; + } + \%hash; + } @{$self->{cond}{-and}} + ]; + } + else { + foreach my $key (keys %{$self->{cond}}) { + $key =~ /([^.]+)$/; + $cond->{$1} = $self->{cond}{$key}; + } + } + } + else { + $self->throw_exception( + "Can't update/delete on resultset with condition unless hash or array"); + } + return $cond; +} + + =head2 update =over 4 @@ -802,8 +856,11 @@ sub update { my ($self, $values) = @_; $self->throw_exception("Values for update must be a hash") unless ref $values eq 'HASH'; + + my $cond = $self->_cond_for_update_delete; + return $self->result_source->storage->update( - $self->result_source->from, $values, $self->{cond} + $self->result_source->from, $values, $cond ); } @@ -852,43 +909,9 @@ sub delete { my ($self) = @_; my $del = {}; - if (!ref($self->{cond})) { - - # No-op. No condition, we're deleting everything - - } elsif (ref $self->{cond} eq 'ARRAY') { - - $del = [ map { my %hash; - foreach my $key (keys %{$_}) { - $key =~ /([^.]+)$/; - $hash{$1} = $_->{$key}; - }; \%hash; } @{$self->{cond}} ]; - - } elsif (ref $self->{cond} eq 'HASH') { - - if ((keys %{$self->{cond}})[0] eq '-and') { - - $del->{-and} = [ map { my %hash; - foreach my $key (keys %{$_}) { - $key =~ /([^.]+)$/; - $hash{$1} = $_->{$key}; - }; \%hash; } @{$self->{cond}{-and}} ]; - - } else { - - foreach my $key (keys %{$self->{cond}}) { - $key =~ /([^.]+)$/; - $del->{$1} = $self->{cond}{$key}; - } - } - - } else { - $self->throw_exception( - "Can't delete on resultset with condition unless hash or array" - ); - } + my $cond = $self->_cond_for_update_delete; - $self->result_source->storage->delete($self->result_source->from, $del); + $self->result_source->storage->delete($self->result_source->from, $cond); return 1; }