Hey,
I have a table which includes a blob and a field for a hash of that blob. I'd like to make atrigger that automatically updates the hash every time the blob is changed, so i figured i would do it with a trigger. I figured the best way to do it would be by overloading new, but that doesnt work... it tells me SUPER::new is no good, which kind of sucks.
eventually i'd try to sdo something like..
sub new{
my $self = SUPER::new(@_);
$self->meta->column->p_value->add_trigger(event => 'on_set',
code => sub { $self->vhash(md5($self->p_value)); },
name => 'keep hash current');
return $self;
}
current code is below.. is this even possible. its been boggling my mind all day long.
package Cantella::PaperKiller::DB::UserPropTypeBin;
use strict;
use base 'Cantella::PaperKiller::DB::DB::Object::AutoBase1';
use Cantella::PaperKiller::DB::User;
use Cantella::PaperKiller::DB::UserProp;
__PACKAGE__->meta->table('user_prop_type_bin');
__PACKAGE__->meta->columns(
user_id => { type => 'integer', not_null => 1 },
prop_id => { type => 'integer', not_null => 1 },
p_value => { type => 'blob', length => 65535 },
vhash => { type => 'character', length => 32, not_null => 1 },
);
__PACKAGE__->meta->primary_key_columns([ 'user_id', 'prop_id', 'vhash' ]);
__PACKAGE__->meta->relationships
(
user => {
type => 'many to one',
class=> 'Cantella::PaperKiller::DB::User',
column_map => { user_id => 'id'}
},
prop => {
type => 'many to one',
class=> 'Cantella::PaperKiller::DB::UserProp',
column_map => { prop_id => 'id'}
}
);
__PACKAGE__->meta->initialize;
sub new{
my $self = SUPER::new(@_);
$self->meta->column->p_value->add_trigger(event => 'on_set',
code => sub { print "TESTING OK\n\n"; },
name => 'keep hash current');
return $self;
}
1;
- [RDBO] triggers and overloading Guillermo Roditi
- Re: [RDBO] triggers and overloading John Siracusa
- Re: [RDBO] triggers and overloading Guillermo Roditi
- Re: [RDBO] triggers and overloading John Siracusa
- Re: [RDBO] triggers and overloading Guillermo Roditi
- Re: [RDBO] triggers and overloading John Siracusa
- Re: [RDBO] triggers and overloa... Guillermo Roditi