[CDBI] Updating a record - slight change proposal

William Ross will at spanner.org
Wed Sep 7 10:33:48 BST 2005


On 7 Sep 2005, at 02:53, Kate Yoak wrote:

> <snip>   for my $col (keys %$vals) {
>       #### ADDING  the unless statement here:
>       #$self->{__Changed}{$col}++ ;
>       $self->{__Changed}{$col}++ unless $self->_attr($col) eq $vals- 
> >{$col};
>    }
>    $self->_attribute_store($vals);
> }
>
> In other words, don't mark something as changed if it hasn't really  
> changed.
>
> What did I break?

The existing or new value will often be an object, which will often  
but not always stringify to the value that would be stored in the  
database, so testing with 'eq' isn't always going to work. You'd  
really have to use the same deflation mechanism as cdbi does when  
updating. I would imagine that Tony considered this before taking the  
easy route, but since he's not here you'd have to ask him directly.

I'm afraid you'll probably have to grep for primary keys when using  
set(). You could either do it beforehand or by adding a  
normalize_column_values() method in subclass:

sub normalize_column_values {
     my ($self, $column_values) = @_;
     delete $column_values->{$_} for $self->primary_columns;
}

I do think you've found a bug, though. The real fix is probably to  
prevent _attribute_delete() from emptying primary key columns, which  
imho aren't really attributes in that sense anyway.

best,

will





More information about the ClassDBI mailing list