Re: Deleting an object on the other side of a has_a

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

From: William McKee
Subject: Re: Deleting an object on the other side of a has_a
Date: 16:15 on 01 Sep 2004
On Wed, Sep 01, 2004 at 11:32:12AM -0400, Perrin Harkins wrote:
> On Wed, 2004-09-01 at 06:02, Peter Pimley wrote:
> > 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;
> > }
> 
> I would probably commit that update before doing the $b->delete. 
> Otherwise, you are potentially creating a referential integrity problem.
> 
> You can also set up a cascading delete here if you want to, using a
> trigger.  Then you wouldn't need to have this special method.

Where would the cascading delete go if you wanted to remove b but not a?
It seems that CDBI is not fully supporting removal of child(?) objects
in a relationship. Perhaps, it would be better to reload a after
deleting b? It seems that CDBI should handle that in the background, no?

As it turns out, the place where we had used this technique has been
rewritten in a way which does not require the need to undef the value of
the relationship. I think your observation that "Class::DBI doesn't
attempt to synchronize your in-memory objects" is where my
misunderstanding has been.


Thanks,
William

        -- 
        Knowmad Services Inc.
http://www.knowmad.com

(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
William McKee 16:15 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