Deleting an object on the other side of a has_a

[prev] [thread] [next] [Date index for 2004/09/01]

From: Peter Pimley
Subject: Deleting an object on the other side of a has_a
Date: 10:02 on 01 Sep 2004
Hello everyone,

I'm tracking down a bug in my program.  I'm lots of weird stuff 
(including some forking) in the area where the bug must be, and one of 
them involves Class::DBI.  I want to remove CDBI from my list of 
posibilities :)  What I'm trying to do is to set a has_a field to 
undef.  It seems to do what I want to the database, but there's no 
explicit mention of it in the documentation.  I have two tables with 
corresponding classes.  They're not doing anything particularly clever:

in pseudo-SQL:
TableA (
    id integer primary key
    my_b integer foreign key references TableB
);

TableB (
    id integer primary key
);

... and then in ClassA.pm in perl....
__PACKAGE__->has_a (my_b, 'ClassB')

So far, so good, everything works as expected.

The bit of code I'm unsure of is where from the point of view of ClassA, 
I try to delete my object of ClassB.  What I'm doing is this (from 
within ClassA.pm)

sub remove_b {
    my $self = shift;  #  so $self is an object of ClassA
    my $b = $self->my_b;
    $self->my_b(undef);  #  there is no documentation for this, but it 
seems to do the correct thing to the database
    $b->delete;
}

Is that the correct way to go about this?  The problem I have is that a 
seperate process accessing the same database does not notice the change, 
and seems to keep the old ClassB object in memory.  As I say, there are 
plenty of other places where this bug might be hiding, so what I'm 
really looking for is just a yes or no answer for whether my remove_b 
method looks safe.

Many thanks in advance,
Peter Pimley.

(message missing)

Deleting an object on the other side of a has_a
Peter Pimley 10:02 on 01 Sep 2004

Re: Deleting an object on the other side of a has_a
Perrin Harkins 16:09 on 01 Sep 2004

Re: Deleting an object on the other side of a has_a
Perrin Harkins 15:32 on 01 Sep 2004

Re: Deleting an object on the other side of a has_a
Perrin Harkins 16:33 on 01 Sep 2004

Re: Deleting an object on the other side of a has_a
Perrin Harkins 17:03 on 01 Sep 2004

Re: Deleting an object on the other side of a has_a
Perrin Harkins 16:42 on 01 Sep 2004

Re: Deleting an object on the other side of a has_a
Perrin Harkins 15:06 on 02 Sep 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52