Re: [CDBI] Using before_update trigger to history
[prev]
[thread]
[next]
[Date index for 2006/01/21]
On 1/20/06, Peter Speltz <peterspeltz@xxxxx.xxx> wrote:
>
> #Then the update trigger would be as simple as
> __PACKAGE__->add_trigger( before_update =3D> sub {
> my $self =3D shift;
> my $dump =3D join ( ', ', map { $_ . ", ". $self->$_ } $self->column=
s );
> $self->add_to_history(dump =3D> $dump);
But code like above no work :( . 2 main problems -. Here is the code
I am using :
# History of this table
__PACKAGE__->has_many(history =3D> __PACKAGE__->_namespace_.'::History' ,
'row_id' , {constraint =3D>{table_name =3D> __PACKAGE__->table}}); =
## WORKS
# update trigger would be as simple as
__PACKAGE__->add_trigger( before_update =3D> sub {
my $self =3D shift;
$self->add_to_history({dump =3D> $self->_dump_data_});
});
# Returns parseable string of data from table
sub _dump_data_ {
my $self =3D shift;
die "Object Method Only!" unless ref $self;
my $dump =3Djoin ( ', ', map { $_ . ", ". $self->_attr($_) } $self->col=
umns );
return $dump;
}
Good news is the has_many , add_to is working as expected.
Problems with above :
1) Getting new data when calling $self->_attr($_) rather than the
old data I want to record in history. I did not expect $self to
contain new data in a before update trigger.
Thinking about it though, the before set trigger is probably where the
old data would be found in $self and simplest thing would be to just
do a select out of DB. This will solve 2)
2) Despite using low level accessor _attr, I 'm still getting
stringifed objects in $dump. I do not understand this .
Back to it.
--
pjs
_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi