From: Michael G Schwern Date: Wed, 13 Feb 2008 06:51:47 +0000 (-0800) Subject: Fix update() so it throws out inflated values, too X-Git-Tag: v0.08240~541^2~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=b57940c54326b7a819d874d0e7b38bf60765d2e9 Fix update() so it throws out inflated values, too --- diff --git a/lib/DBIx/Class/CDBICompat/LazyLoading.pm b/lib/DBIx/Class/CDBICompat/LazyLoading.pm index b3d18e9..0b6691b 100644 --- a/lib/DBIx/Class/CDBICompat/LazyLoading.pm +++ b/lib/DBIx/Class/CDBICompat/LazyLoading.pm @@ -21,7 +21,8 @@ sub update { my $ret = $self->next::method(@_); - delete $self->{_column_data}{$_} for @dirty_columns; + delete $self->{_column_data}{$_} for @dirty_columns; + delete $self->{_inflated_column}{$_} for @dirty_columns; return $ret; } diff --git a/t/cdbi-t/04-lazy.t b/t/cdbi-t/04-lazy.t index 5fd18f2..15e1e1c 100644 --- a/t/cdbi-t/04-lazy.t +++ b/t/cdbi-t/04-lazy.t @@ -13,7 +13,7 @@ BEGIN { next; } eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 27); + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 30); } INIT { @@ -99,4 +99,36 @@ ok($@, $@); }, undef, 23, $l->this); is $l->oop, 23; + + $l->delete; +} + + +# Now again for inflated values +{ + Lazy->has_a( + orp => 'Date::Simple', + inflate => sub { Date::Simple->new(shift . '-01-01') }, + deflate => 'format' + ); + + my $l = Lazy->create({ + this => 89, + that => 2, + orp => 1998, + }); + + $l->orp(2007); + is $l->orp, '2007-01-01'; # make sure it's inflated + $l->update; + + ok $l->db_Main->do(qq{ + UPDATE @{[ $l->table ]} + SET orp = ? + WHERE this = ? + }, undef, 1942, $l->this); + + is $l->orp, '1942-01-01'; + + $l->delete; }