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

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

From: William McKee
Subject: Re: Deleting an object on the other side of a has_a
Date: 14:47 on 02 Sep 2004
On Thu, Sep 02, 2004 at 09:50:10AM +0100, Peter Pimley wrote:
> Well, from what I could see from the documentation, might_have seems to 
> be for adding extra fields to an existing object, rather than acting 
> like a pointer (spot the C++ coder ;) to another object.

Good point. The wording can be confusing here. Your has_a example *might
have* (notice no connecting _) a related record in TableB. If this is
the case, perhaps you should have a has_many relationship in TableA
and store the id of TableA in TableB.

I'm not criticizing your example as much as trying to understand good
database design. It seems confusing to have a has_a relation without a
related record. And neither CDBI nor SQL seem to enforce any hard and
fast rules concerning relationships (which is the Perl way;) but can
make things confusing for database design beginners like myself. I guess
this trails off into normalization and 3NF, BCNF, etc which are clearly
off-topic.


> So long as you can set a has_a field to undef, then has_a is definately 
> what I want.

Neither SQL nor CDBI seem to prevent you from doing this. Of course Perl
doesn't prevent you from writing sloppy code but we all know that it's
not a good idea <g>. My philosophy is that if it works for you, use it
until you know better.


> I'll try calling remove_from_object_index on my 'bad' object, or 
> possibly call clear_object_index.  This is all happening from within 
> Mason / mod_perl, so it's possible that stale objects are hanging around 
> between browser hits.  I'm nowhere near performance-bound, so any 
> overheads will not be a problem.

My money is on Perrin's observation that one process is modifying your
record without the knowledge of another process. If the
remove_from_object_index and clear_object_index don't help you, you may
want to try to reload the record via a retrieve().


> I'll let you know how I get on!

I'll be interested to hear the results.


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
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
William McKee 14:47 on 02 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