From: Ash Berlin Date: Mon, 5 Feb 2007 12:29:52 +0000 (+0000) Subject: Backed out my r3073, and doc'd the fact that it takes a hashref that might be changed X-Git-Tag: v0.08010~187 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=d5d833d959dea814d49ea3d15010cb42ab6ee310 Backed out my r3073, and doc'd the fact that it takes a hashref that might be changed --- diff --git a/lib/DBIx/Class/Relationship/Accessor.pm b/lib/DBIx/Class/Relationship/Accessor.pm index e98c9a2..b77ce00 100644 --- a/lib/DBIx/Class/Relationship/Accessor.pm +++ b/lib/DBIx/Class/Relationship/Accessor.pm @@ -84,7 +84,6 @@ sub new { sub update { my ($obj, $attrs, @rest) = @_; - $attrs = { %$attrs} if $attrs; # Take copy so we dont change passed hashref my $info; foreach my $key (keys %{$attrs||{}}) { next unless $info = $obj->relationship_info($key); diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 4a55f50..e6e5ebc 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -100,19 +100,20 @@ sub in_storage { =head2 update - $obj->update; + $obj->update \%columns?; Must be run on an object that is already in the database; issues an SQL UPDATE query to commit any changes to the object to the database if required. +Also takes an options hashref of C<< column_name => value> pairs >> to update +first. But be aware that this hashref might be edited in place, so dont rely on +it being the same after a call to C. + =cut sub update { my ($self, $upd) = @_; - # Create a copy so we dont mess with original - $upd = { %$upd } if $upd; - $self->throw_exception( "Not in database" ) unless $self->in_storage; my $ident_cond = $self->ident_condition; $self->throw_exception("Cannot safely update a row in a PK-less table") diff --git a/t/68inflate.t b/t/68inflate.t index 9cbaab9..2e7c374 100644 --- a/t/68inflate.t +++ b/t/68inflate.t @@ -11,7 +11,7 @@ my $schema = DBICTest->init_schema(); eval { require DateTime }; plan skip_all => "Need DateTime for inflation tests" if $@; -plan tests => 22; +plan tests => 20; DBICTest::Schema::CD->inflate_column( 'year', { inflate => sub { DateTime->new( year => shift ) }, @@ -90,12 +90,6 @@ ok(!$@, 'update using scalarref ok'); $cd = $schema->resultset("CD")->find(3); is($cd->year->year, $before_year + 1, 'deflate ok'); -my $upd = { 'year' => $now->truncate(to => 'month'), title => 'An Updated Title' }; -my $upd_copy = { %$upd }; -eval { $cd->update($upd) }; -ok(!$@, 'update worked okay'); -ok(exists $upd->{year} && $upd->{year} == $upd_copy->{year}, "update doesn't change passed hashref"); - # discard_changes test $cd = $schema->resultset("CD")->find(3); # inflate the year