Re: before_create trigger problems
[prev]
[thread]
[next]
[Date index for 2004/12/22]
--On Tuesday, December 21, 2004 11:28:41 AM EST -0800 Emile Aben
<emileaben@xxxxx.xxx> wrote:
>
>> > Further on in the triggered sub I sometimes have
>> to
>> > create a new object in the database, and I'm
>> currently
>> > unable to get this working. My best try is:
>> >
>> > if ($new_end && $new_start >=
>> > $old_start && (!$old_end || $new_end <= $old_end )
>> ) {
>> > # case: nnnn
>> > # ooooooooo(...)
>> > # solution: cut old in 2
>> > print STDERR " nnnn\n";
>> > print STDERR " ooooooooo(...)\n";
>> > my $old2 = $old->copy();
>> > $old2->_attribute_set("start_date", $new_end +
>> 1 );
>> > $old2->update();
>> > $old->_attribute_set("end_date", $new_start - 1
>> );
>> > $old->update();
>> > }
>> >
>> > This get's stuck on line 51 in Trigger.pm again:
>> > Can't retrieve a reference at
>> >
>>
> /usr/local/perl-5.6.0/lib/site_perl/5.6.0/Class/Trigger.pm
>> > line 51
>>
>> Hmm. Do you happen to know whether the copy() or
>> the update() triggers
>> this error?
>
> It's the copy() that causes this. Is there another way
I'd guess this is another manifestation of the "don't inflate your primary
key" restriction. If you PK stringifies to what's in the dataabase, we
could fix it with a fairly straightforward patch.
> to copy/clone without side-effects, and that
You'd need to clone the object by hand, using something like
my(@pk) = $old->primary_columns;
my(%data) = map { "$_" => $old->get("$_") } $old->all_columns;
delete @data{@pk};
my $new = $old->create(\%data);
--
Regards,
Charles Bailey < bailey _at_ newman _dot_ upenn _dot_ edu >
Newman Center at the University of Pennsylvania
|
(message missing)
|