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);
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")
eval { require DateTime };
plan skip_all => "Need DateTime for inflation tests" if $@;
-plan tests => 20;
+plan tests => 22;
DBICTest::Schema::CD->inflate_column( 'year',
{ inflate => sub { DateTime->new( year => shift ) },
$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