Re: select trigger and warnings
[prev]
[thread]
[next]
[Date index for 2004/11/18]
Thanks. I've modified the triggers to call $self->_attribute_store.
The 'before_create' trigger works fine. The problem now is that I the
'select' trigger seems to be called twice! (I think one for 'construct'
and one for '_flesh'), thus the values returned to the app are not
correct. I added another trigger with a test method to illustrate:
In MyPackage::DBI:
sub test {
my $self = shift;
my $val = "Vlan ". $self->description;
$self->_attribute_store( description => $val );
}
Vlan->add_trigger( select => \&test );
In test.pl:
...
foreach my $o (Vlan->retrieve_all){
print " desc: ", $o->description, "\n";
}
# perl test.pl
desc: Vlan Vlan 1
desc: Vlan Vlan 60
desc: Vlan Vlan 2060
desc: Vlan Vlan 170
desc: Vlan Vlan 190
desc: Vlan Vlan 252
desc: Vlan Vlan 182
desc: Vlan Vlan 194
desc: Vlan Vlan 192
desc: Vlan Vlan 198
desc: Vlan Vlan 188
desc: Vlan Vlan 168
desc: Vlan Vlan 184
desc: Vlan Vlan 172
desc: Vlan Vlan 116
desc: Vlan Vlan 186
desc: Vlan Vlan 144
desc: Vlan Vlan 196
Am I doing something wrong? Or is this a bug?
Again, thanks for your help.
cv
Re: select trigger and warnings Tony Bowden
From: Tony Bowden <tony-cdbitalk@xxxxx.xxx>
To: cdbi-talk <cdbi-talk@xxxxxx.xxxxx.xxx>
Subject: Re: select trigger and warnings
Date: Wed, 17 Nov 2004 11:01:46 +0000
Mail-followup-to: cdbi-talk <cdbi-talk@xxxxxx.xxxxx.xxx>
References: <1100630616.28168.26.camel@xxxxxxxx.xxxxxxx.xxx>
Reply-to: tony@xxxxx.xxx
User-agent: Mutt/1.5.5.1+cvs20040105i
On Tue, Nov 16, 2004 at 10:43:36AM -0800, Carlos Vicente wrote:
> Ipblock->add_trigger( deflate_for_create => \&ip2int );
> Ipblock->add_trigger( deflate_for_update => \&ip2int );
> Ipblock->add_trigger( select => \&int2ip );
> These methods do some calculations and set the value using
> $self->address($value).
In a before_create trigger you need to use
$self->_attribute_store(address => $value)
rather than calling the ->address method directly.
Calling ->address() will set the address field to be modified at the
next UPDATE, but create doesn't call UPDATE just INSERT. So when the
object goes out of scope you'll get the normal warnings about having an
altereredf ield not having been written to the database.
This isn't particularly ideal, but I don't have a good solution at this
point.
Tony
|
|
Re: select trigger and warnings
Carlos Vicente 01:49 on 18 Nov 2004
|