sub set_column {
my $self = shift;
my ($column) = @_;
+ my $old = $self->get_column($column);
my $ret = $self->store_column(@_);
- $self->{_dirty_columns}{$column} = 1;
+ $self->{_dirty_columns}{$column} = 1 unless defined $old && $old eq $ret;
return $ret;
}
return $class->retrieve_from_sql( '1' );
}
+sub is_changed {
+ return keys %{shift->{_dirty_columns} || {}};
+}
+
1;
=back
--- /dev/null
+use strict;
+use Test::More;
+
+BEGIN {
+ eval "use DBD::SQLite";
+ plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 4);
+}
+
+use lib qw(t/lib);
+
+use_ok('DBICTest');
+
+my $art = DBICTest::Artist->retrieve(1);
+
+isa_ok $art => 'DBICTest::Artist';
+
+my $name = 'Caterwauler McCrae';
+
+ok($art->name($name) eq $name, 'update');
+
+{
+ my @changed_keys = $art->is_changed;
+ is( scalar (@changed_keys), 0, 'field changed but same value' );
+}
+
+$art->discard_changes;