From: Matt S Trout Date: Sun, 10 Jan 2010 05:36:42 +0000 (+0000) Subject: update command X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Data-Store-old.git;a=commitdiff_plain;h=48d91d77fd61a1d85e35901cc4d101b5066c8544 update command --- diff --git a/lib/DBIx/Data/Collection/Set.pm b/lib/DBIx/Data/Collection/Set.pm index 4d90294..7e71b8e 100644 --- a/lib/DBIx/Data/Collection/Set.pm +++ b/lib/DBIx/Data/Collection/Set.pm @@ -155,7 +155,7 @@ method remove ($old) { } method _remove_from_store ($old) { - $self->_store->new_delete_command($self->_deflate($old))->execute; + $self->_store->new_delete_command($self->_deflate($old))->execute } method _remove_from_caches ($old) { @@ -164,4 +164,13 @@ method _remove_from_caches ($old) { $old } +## update + +method _update_in_store ($obj) { + # this is currently a call command but we should think about it + # being a row command so that we can have RETURNING or other + # mechanisms handle things like set-on-update datetime values + $self->_store->new_update_command($self->_deflate($obj))->execute +} + 1; diff --git a/t/01basic_collection.t b/t/01basic_collection.t index 65e55ce..94ccb0f 100644 --- a/t/01basic_collection.t +++ b/t/01basic_collection.t @@ -103,4 +103,21 @@ $set = make_set; is_deeply([ sort_set $set->flatten ], \@expect, 'new row still gone on reload'); +$set = make_set {}, { + update_sql => q{UPDATE person SET name = ? WHERE id = ?}, + update_argument_order => [ qw(name id) ] +}; + +my ($pterry) = grep $_->{name} eq 'Pterry', $set->flatten; + +$pterry->{name} = 'Sir Pterry'; # http://xrl.us/bgse8s + +$set->_update_in_store($pterry); + +$set = make_set; + +my ($fresh_pterry) = grep $_->{name} =~ /Pterry/, $set->flatten; + +is($fresh_pterry->{name}, 'Sir Pterry', 'Update persisted correctly'); + done_testing;