Behavior of validate_column_values when called from copy()

[prev] [thread] [next] [Date index for 2005/06/28]

From: Rod McChesney
Subject: Behavior of validate_column_values when called from copy()
Date: 02:08 on 28 Jun 2005
[I sent this out a couple of times before and got no response. Now
that 1.0 is looming, I'm hoping someone will reply...]

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 =3D 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 =3D shift;
   $class =3D 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

possible improvement of Live_Objects cache
Jasper Cramwinckel 10:44 on 27 Jun 2005

Behavior of validate_column_values when called from copy()
Rod McChesney 02:08 on 28 Jun 2005

Re: possible improvement of Live_Objects cache
Perrin Harkins 04:28 on 01 Jul 2005

Re: possible improvement of Live_Objects cache
Jasper Cramwinckel 10:08 on 11 Jul 2005

Re: possible improvement of Live_Objects cache
Perrin Harkins 17:39 on 11 Jul 2005

Generated at 16:35 on 28 Jul 2005 by mariachi v0.52