From: Cory G Watson Date: Thu, 19 Jun 2008 13:06:57 +0000 (+0000) Subject: Add make_column_dirty to Row (per request from #dbix-class questions) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6dbea98e46d81ecc75a3d0dad994aef882426d35;p=dbsrgits%2FDBIx-Class-Historic.git Add make_column_dirty to Row (per request from #dbix-class questions) --- diff --git a/Changes b/Changes index c416169..4fb3d24 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class + - add a make_column_dirty method to Row to force updates - throw a clear exception when user tries multi-has_many prefetch - SQLT parser prefixes index names with ${table}_idx_ to avoid clashes - mark ResultSetManager as deprecated and undocument it diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index ffe0359..d58d957 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -451,6 +451,20 @@ sub get_dirty_columns { keys %{$self->{_dirty_columns}}; } +=head2 make_column_dirty + +Marks a column dirty regardless if it has really changed. Throws an +exception if the column does not exist. + +=cut +sub make_column_dirty { + my ($self, $column) = @_; + + $self->throw_exception( "No such column '${column}'" ) + unless exists $self->{_column_data}{$column} || $self->has_column($column); + $self->{_dirty_columns}{$column} = 1; +} + =head2 get_inflated_columns my %inflated_data = $obj->get_inflated_columns; diff --git a/t/60core.t b/t/60core.t index 456dc7b..52e6ead 100644 --- a/t/60core.t +++ b/t/60core.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 78; +plan tests => 84; eval { require DateTime::Format::MySQL }; my $NO_DTFM = $@ ? 1 : 0; @@ -37,10 +37,26 @@ $art->name('We Are In Rehab'); is($art->name, 'We Are In Rehab', "Accessor update ok"); +my %dirty = $art->get_dirty_columns(); +cmp_ok(scalar(keys(%dirty)), '==', 1, '1 dirty column'); +ok(grep($_ eq 'name', keys(%dirty)), 'name is dirty'); + is($art->get_column("name"), 'We Are In Rehab', 'And via get_column'); ok($art->update, 'Update run'); +my %not_dirty = $art->get_dirty_columns(); +cmp_ok(scalar(keys(%not_dirty)), '==', 0, 'Nothing is dirty'); + +eval { + my $ret = $art->make_column_dirty('name2'); +}; +ok(defined($@), 'Failed to make non-existent column dirty'); +$art->make_column_dirty('name'); +my %fake_dirty = $art->get_dirty_columns(); +cmp_ok(scalar(keys(%fake_dirty)), '==', 1, '1 fake dirty column'); +ok(grep($_ eq 'name', keys(%fake_dirty)), 'name is fake dirty'); + my $record_jp = $schema->resultset("Artist")->search(undef, { join => 'cds' })->search(undef, { prefetch => 'cds' })->next; ok($record_jp, "prefetch on same rel okay");