X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=7611945b3069f4e2ef47c1892d00d1c1f42c5563;hb=038af71cf6f6c77cb1380378d4887a7da03fe2b2;hp=085e643b6ad6a126d8715bf6fdcfbb93abe9c237;hpb=07a287ced6e57fabab6c2f9f0b6177c91f983a14;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 085e643..7611945 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1121,6 +1121,11 @@ An accessor for the class to use when creating row objects. Defaults to C<< result_source->result_class >> - which in most cases is the name of the L<"table"|DBIx::Class::Manual::Glossary/"ResultSource"> class. +Note that changing the result_class will also remove any components +that were originally loaded in the source class via +L. Any overloaded methods +in the original source class will not run. + =cut sub result_class { @@ -1310,49 +1315,8 @@ sub _cond_for_update_delete { # No-op. No condition, we're updating/deleting everything return $cond unless ref $full_cond; - if (ref $full_cond eq 'ARRAY') { - $cond = [ - map { - my %hash; - foreach my $key (keys %{$_}) { - $key =~ /([^.]+)$/; - $hash{$1} = $_->{$key}; - } - \%hash; - } @{$full_cond} - ]; - } - elsif (ref $full_cond eq 'HASH') { - if ((keys %{$full_cond})[0] eq '-and') { - $cond->{-and} = []; - - my @cond = @{$full_cond->{-and}}; - for (my $i = 0; $i < @cond; $i++) { - my $entry = $cond[$i]; - - my $hash; - if (ref $entry eq 'HASH') { - $hash = $self->_cond_for_update_delete($entry); - } - else { - $entry =~ /([^.]+)$/; - $hash->{$1} = $cond[++$i]; - } - - push @{$cond->{-and}}, $hash; - } - } - else { - foreach my $key (keys %{$full_cond}) { - $key =~ /([^.]+)$/; - $cond->{$1} = $full_cond->{$key}; - } - } - } - else { - $self->throw_exception( - "Can't update/delete on resultset with condition unless hash or array" - ); + foreach my $pk ($self->result_source->primary_columns) { + $cond->{$pk} = { -in => $self->get_column($pk)->as_query }; } return $cond; @@ -1380,13 +1344,8 @@ sub update { $self->throw_exception("Values for update must be a hash") unless ref $values eq 'HASH'; - carp( 'WARNING! Currently $rs->update() does not generate proper SQL' - . ' on joined resultsets, and may affect rows well outside of the' - . ' contents of $rs. Use at your own risk' ) - if ( $self->{attrs}{seen_join} ); - my $cond = $self->_cond_for_update_delete; - + return $self->result_source->storage->update( $self->result_source, $values, $cond ); @@ -1434,10 +1393,6 @@ to run. See also L. delete may not generate correct SQL for a query with joins or a resultset chained from a related resultset. In this case it will generate a warning:- - WARNING! Currently $rs->delete() does not generate proper SQL on - joined resultsets, and may delete rows well outside of the contents - of $rs. Use at your own risk - In these cases you may find that delete_all is more appropriate, or you need to respecify your query in a way that can be expressed without a join. @@ -1447,10 +1402,7 @@ sub delete { my ($self) = @_; $self->throw_exception("Delete should not be passed any arguments") if $_[1]; - carp( 'WARNING! Currently $rs->delete() does not generate proper SQL' - . ' on joined resultsets, and may delete rows well outside of the' - . ' contents of $rs. Use at your own risk' ) - if ( $self->{attrs}{seen_join} ); + my $cond = $self->_cond_for_update_delete; $self->result_source->storage->delete($self->result_source, $cond); @@ -2382,12 +2334,20 @@ sub _resolved_attrs { # build columns (as long as select isn't set) into a set of as/select hashes unless ( $attrs->{select} ) { @colbits = map { - ( ref($_) eq 'HASH' ) ? $_ - : { - ( - /^\Q${alias}.\E(.+)$/ ? $1 - : $_ - ) => ( /\./ ? $_ : "${alias}.$_" ) + ( ref($_) eq 'HASH' ) + ? $_ + : { + ( + /^\Q${alias}.\E(.+)$/ + ? "$1" + : "$_" + ) + => + ( + /\./ + ? "$_" + : "${alias}.$_" + ) } } ( ref($attrs->{columns}) eq 'ARRAY' ) ? @{ delete $attrs->{columns}} : (delete $attrs->{columns} || $source->columns ); }