Skip Menu |

This queue is for tickets about the Class-DBI CPAN distribution.

Report information
The Basics
Id: 13747
Status: new
Priority: 0/
Queue: Class-DBI

People
Owner: Nobody in particular
Requestors: davekam [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: obvious way to change columns in before_create / before_update doesn't work
I have a Class::DBI table where I want to keep track, for each row, of its creation and modification date. My first thought was to implement this using before_create and before_update triggers. At first this seemed to work, but when I tried using the classes in Maypole I experienced unexpected infinite loop hangs, due to its turning on autoupdate. It turns out that if you set a column in one of the accessor methods within a before_update trigger, and autoupdate is on, it causes an infinite loop. Within a before_create trigger it just seems to not work at all, although my experiences have been mixed here and I'm not sure of the cause. At any rate, from perusing the mailing list I came across the following solution: sub before_create { my $self = shift; my $t = gmtime; $self->_attribute_set(c_time => $t); $self->_attribute_set(m_time => $t); } sub before_update { my $self = shift; my $t = gmtime; $self->_attribute_set(m_time => $t); } (Where c_time and m_time are inflated to Time::Piece and deflated to appropriate strings.) So, while it's possible for me to do what I want, there's nothing in the Class::DBI documentation to tell me how to do it or what the pitfalls might be. At any rate, it would be nice if there were a standard way to accomplish this. For it to just work with the accessors might be too much to ask, as I realize the various difficulties, but these issues should at least be documented! That is, what you can and cannot do within a trigger of a given type.
Date: Mon, 18 Jul 2005 12:17:38 +0100
From: Tony Bowden <tony [...] kasei.com>
To: Guest via RT <bug-Class-DBI [...] rt.cpan.org>
Subject: Re: [cpan #13747] obvious way to change columns in before_create / before_update doesn't work
RT-Send-Cc:
On Mon, Jul 18, 2005 at 07:10:50AM -0400, Guest via RT wrote: Show quoted text
> So, while it's possible for me to do what I want, there's nothing in > the Class::DBI documentation to tell me how to do it or what the pitfalls > might be.
It is described, albeit rather obliquely, in the "LOW-LEVEL DATA ACCESS" section of the docs. Show quoted text
> At any rate, it would be nice if there were a standard way to > accomplish this.
The main issue is that in a before_create trigger the object hasn't been created yet, and thus you won't be able to do all the things on it you might expect. There's an oblique reference to this again in the before_create docs. But yes, I agree it should be made more explicit. Suggestions welcome. Tony