X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRow.pm;h=1b66e35b436f8c37d05ba1a3a79016390c8702d3;hb=52416317;hp=4bdfd519f22611b18dd8f08e4c57f1993c422a84;hpb=bbdda28109ffb2442af84b3cbe5c4921714a52dd;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 4bdfd51..1b66e35 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -798,15 +798,14 @@ See L for how to setup inflation. sub get_inflated_columns { my $self = shift; - my %loaded_colinfo = (map - { $_ => $self->column_info($_) } - (grep { $self->has_column_loaded($_) } $self->columns) - ); + my $loaded_colinfo = $self->columns_info ([ + grep { $self->has_column_loaded($_) } $self->columns + ]); my %inflated; - for my $col (keys %loaded_colinfo) { - if (exists $loaded_colinfo{$col}{accessor}) { - my $acc = $loaded_colinfo{$col}{accessor}; + for my $col (keys %$loaded_colinfo) { + if (exists $loaded_colinfo->{$col}{accessor}) { + my $acc = $loaded_colinfo->{$col}{accessor}; $inflated{$col} = $self->$acc if defined $acc; } else { @@ -815,7 +814,7 @@ sub get_inflated_columns { } # return all loaded columns with the inflations overlayed on top - return ($self->get_columns, %inflated); + return %{ { $self->get_columns, %inflated } }; } sub _is_column_numeric { @@ -823,7 +822,7 @@ sub _is_column_numeric { my $colinfo = $self->column_info ($column); # cache for speed (the object may *not* have a resultsource instance) - if (not defined $colinfo->{is_numeric} && $self->_source_handle) { + if (! defined $colinfo->{is_numeric} && $self->_source_handle) { $colinfo->{is_numeric} = $self->result_source->schema->storage->is_datatype_numeric ($colinfo->{data_type}) ? 1 @@ -1025,9 +1024,11 @@ sub copy { my ($self, $changes) = @_; $changes ||= {}; my $col_data = { %{$self->{_column_data}} }; + + my $colinfo = $self->columns_info([ keys %$col_data ]); foreach my $col (keys %$col_data) { delete $col_data->{$col} - if $self->result_source->column_info($col)->{is_auto_increment}; + if $colinfo->{$col}{is_auto_increment}; } my $new = { _column_data => $col_data }; @@ -1371,20 +1372,36 @@ sub get_from_storage { return $resultset->find($ident_cond); } -=head2 discard_changes ($attrs) +=head2 discard_changes ($attrs?) + + $row->discard_changes + +=over + +=item Arguments: none or $attrs + +=item Returns: self (updates object in-place) + +=back Re-selects the row from the database, losing any changes that had -been made. Throws an exception if a proper WHERE clause identifying +been made. Throws an exception if a proper C clause identifying the database row can not be constructed (i.e. if the original object does not contain its entire -L -). +L). This method can also be used to refresh from storage, retrieving any changes made since the row was last read from storage. -$attrs is expected to be a hashref of attributes suitable for passing as the -second argument to $resultset->search($cond, $attrs); +$attrs, if supplied, is expected to be a hashref of attributes suitable for passing as the +second argument to C<< $resultset->search($cond, $attrs) >>; + +Note: If you are using L as your +storage, please kept in mind that if you L on a row that you +just updated or created, you should wrap the entire bit inside a transaction. +Otherwise you run the risk that you insert or update to the master database +but read from a replicant database that has not yet been updated from the +master. This will result in unexpected results. =cut @@ -1445,34 +1462,6 @@ sub throw_exception { Returns the primary key(s) for a row. Can't be called as a class method. Actually implemented in L -=head2 discard_changes - - $row->discard_changes - -=over - -=item Arguments: none - -=item Returns: nothing (updates object in-place) - -=back - -Retrieves and sets the row object data from the database, losing any -local changes made. - -This method can also be used to refresh from storage, retrieving any -changes made since the row was last read from storage. Actually -implemented in L - -Note: If you are using L as your -storage, please kept in mind that if you L on a row that you -just updated or created, you should wrap the entire bit inside a transaction. -Otherwise you run the risk that you insert or update to the master database -but read from a replicant database that has not yet been updated from the -master. This will result in unexpected results. - -=cut - 1; =head1 AUTHORS @@ -1484,3 +1473,5 @@ Matt S. Trout You may distribute this code under the same terms as Perl itself. =cut + +1;