How validate_column_values is called when copying
[prev]
[thread]
[next]
[Date index for 2005/04/08]
Using CDBI 0.96 I'm running into what I believe is a bug. I'm
overriding validate_column_values to hook into an existing field
validation setup. When I copy an object, validate_column_values is
called on the yet-to-be-created copy. According to the pod:
Before an object is assigned data from the application (via create or a
set accessor) the validate_column_values() method is called with a
reference to a hash containing the column names and the new values which
are to be assigned.
The method is called as an instance method when the values of an
existing object are being changed, and as a class method when a new
object is being created.
However, when copy is called, it calls create as an instance method:
sub copy {
my $self = shift;
return $self->create($self->_data_hash(@_));
}
So create ends up calling validate_column_values as an instance method
as well, with the cloned object appearing as $self. This means there's
no way to distinguish creation from update in validation, AFAICT.
This seems borne out by my workaround, which is to override create
like so:
sub create {
my $class = shift;
$class = ref($class) || $class;
return $class->SUPER::create(@_);
}
Is this in fact a bug, or am I confused about how it's supposed to work?
Thanks,
Rod
|
|
How validate_column_values is called when copying
Rod McChesney 23:58 on 08 Apr 2005
|