From: Peter Rabbitson Date: Sun, 21 Jun 2009 12:37:56 +0000 (+0000) Subject: make_column_dirty fix X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=497d874ac78f5b6bba1309001f62c299a9419499;p=dbsrgits%2FDBIx-Class-Historic.git make_column_dirty fix --- diff --git a/Changes b/Changes index 3bd0d4f..5ebf0e7 100644 --- a/Changes +++ b/Changes @@ -6,7 +6,9 @@ Revision history for DBIx::Class nonexisting prefetch - Fixed the prefetch with limit bug - New resultsed method count_rs, returns a ::ResultSetColumn - returning a single count value + which in turn returns a single count value + - make_column_dirty() now overwrites the deflated value with an + inflated one if such exists 0.08107 2009-06-14 08:21:00 (UTC) - Fix serialization regression introduced in 0.08103 (affects diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index bde2989..72bb2fc 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -710,7 +710,21 @@ sub make_column_dirty { $self->throw_exception( "No such column '${column}'" ) unless exists $self->{_column_data}{$column} || $self->has_column($column); + + # the entire clean/dirty code relieas on exists, not on true/false + return 1 if exists $self->{_dirty_columns}{$column}; + $self->{_dirty_columns}{$column} = 1; + + # if we are just now making the column dirty, and if there is an inflated + # value, force it over the deflated one + if (exists $self->{_inflated_column}{$column}) { + $self->store_column($column, + $self->_deflated_column( + $column, $self->{_inflated_column}{$column} + ) + ); + } } =head2 get_inflated_columns diff --git a/t/inflate/serialize.t b/t/inflate/serialize.t index 59c0997..c2be971 100644 --- a/t/inflate/serialize.t +++ b/t/inflate/serialize.t @@ -32,7 +32,7 @@ foreach my $serializer (@serializers) { plan (skip_all => "No suitable serializer found") unless $selected; -plan (tests => 8); +plan (tests => 11); DBICTest::Schema::Serialized->inflate_column( 'serialized', { inflate => $selected->{inflater}, deflate => $selected->{deflater}, @@ -84,3 +84,17 @@ is_deeply($object->serialized, $struct_hash, 'inflated hash matches original'); ok($object->update( { serialized => $struct_array } ), 'arrayref deflation'); ok($inflated = $object->serialized, 'arrayref inflation'); is_deeply($inflated, $struct_array, 'inflated array matches original'); + + +#===== make sure make_column_dirty ineracts reasonably with inflation +$object = $rs->first; +$object->update ({serialized => { x => 'y'}}); + +$object->serialized->{x} = 'z'; # change state without notifying $object +ok (!$object->get_dirty_columns, 'no dirty columns yet'); +is_deeply ($object->serialized, { x => 'z' }, 'object data correct'); + +$object->make_column_dirty('serialized'); +$object->update; + +is_deeply ($rs->first->serialized, { x => 'z' }, 'changes made it to the db' );