From: Peter Rabbitson Date: Sun, 27 Jul 2014 22:39:19 +0000 (+0200) Subject: Fix set_column on non-native (+columns) selections (RT#86685) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=57e9c142d79b612040929c7038b42a8d8bba78df;p=dbsrgits%2FDBIx-Class-Historic.git Fix set_column on non-native (+columns) selections (RT#86685) --- diff --git a/Changes b/Changes index 7f174c4..fc72d6b 100644 --- a/Changes +++ b/Changes @@ -39,6 +39,7 @@ Revision history for DBIx::Class up by create() and populate() - Ensure definitive condition extractor handles bizarre corner cases without bombing out (RT#93244) + - Fix set_column on non-native (+columns) selections (RT#86685) - Fix set_inflated_column incorrectly handling \[] literals (GH#44) - Ensure that setting a column to a literal invariably marks it dirty - Work around exception objects with broken string overloading in one diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 03c78fe..63630fd 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -428,6 +428,8 @@ jnapiorkowski: John Napiorkowski jon: Jon Schutz +Joe Carlson + jshirley: J. Shirley kaare: Kaare Rasmussen diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index d356218..6dfe30e 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -890,7 +890,10 @@ sub get_inflated_columns { } sub _is_column_numeric { - my ($self, $column) = @_; + my ($self, $column) = @_; + + return undef unless $self->result_source->has_column($column); + my $colinfo = $self->result_source->column_info ($column); # cache for speed (the object may *not* have a resultsource instance) @@ -942,9 +945,10 @@ sub set_column { my $dirty = $self->{_dirty_columns}{$column} || - $self->in_storage # no point tracking dirtyness on uninserted data + ( $self->in_storage # no point tracking dirtyness on uninserted data ? ! $self->_eq_column_values ($column, $old_value, $new_value) : 1 + ) ; if ($dirty) { diff --git a/t/row/set_extra_column.t b/t/row/set_extra_column.t new file mode 100644 index 0000000..0debaaf --- /dev/null +++ b/t/row/set_extra_column.t @@ -0,0 +1,32 @@ +use strict; +use warnings; + +use Test::More; + +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $rs_with_avg = $schema->resultset('CD')->search({}, { + '+columns' => { avg_year => $schema->resultset('CD')->get_column('year')->func_rs('avg')->as_query }, + order_by => 'cdid', +}); + +for my $in_storage (1, 0) { + my $cd = $rs_with_avg->first; + + ok ! $cd->is_column_changed('avg_year'), 'no changes'; + + $cd->in_storage($in_storage); + + ok ! $cd->is_column_changed('avg_year'), 'still no changes'; + + $cd->set_column( avg_year => 42 ); + $cd->set_column( avg_year => 69 ); + + ok $cd->is_column_changed('avg_year'), 'changed'; + is $cd->get_column('avg_year'), 69, 'correct value' +} + +done_testing;