R: [Zope] Discussion: Best practice site struture (LONG)

Max M maxm@mxm.dk
Thu, 11 Apr 2002 10:33:45 +0200


Luca Olivetti wrote:

> Max M wrote:
>
>>> The management interface should show dangling links instead of just 
>>> hiding them. 
>>
>>
>> Not in the current implementation. The product currently deletes 
>> relations that no longer has valid objects. I did this so that you 
>> cannot remove an object with one meta_type and add one with another 
>> meta_type but the same id. This, I guess could seriously screw up the 
>> app.
>
>
> Maybe I was doing something stupid (with all that banging my head on 
> the wall trying to learn zope+cmf+zpt+writing python products all at 
> once ;-) but this is not what I saw: before I implemented 
> manage_beforeDelete in my objects, I deleted one, I went to the 
> management interface of the mxmRelation and saw that the relation 
> wasn't there anymore -- good.
> Then I created a new object with the same id and when I went to 
> display it the old relation was still in place -- bad. 


You are indeed right that it *can* happen. There is no way in Zope to 
subscribe to an object. So the relations class cannot know if an object 
is deleted before it tries to fetch it via the path. If the relations 
class cannot find an object it deletes it then.

This means that if a new object is created between the old one being 
deleted and the next time the relations class tries to fetch it, that 
the link will still be there. That is not ideal of course.

> Since I didn't know of manage_beforeDelete at the time, in my object 
> creation method I just put a call to delete dangling relations :-)


The correct way to ensure that there are no dangling relations naturally 
is to create a method in any product being related to like (from the top 
of my head)::

    def manage_beforeDelete(self):
        self.relations.delete(self)

Then things happens cleanly.

> Well, there are not so many cases and with postgres (not that I'm an 
> expert of it, it just happens that I read a tutorial about foreign 
> keys and referential integrity ;-) you can define what happens when 
> you delete a record another table depends on:
>
> 1) do nothing
> 2) cascade delete (i.e.delete the record and all records depending on 
> it, useful for example if you're trying to delete an invoice and its 
> lines)
> 3) don't allow deleting the record
>
> and that's it. But, as you say, that's not possible without 
> modifications to zope core. 


I believe that will be more complex in Zope as objects are not as simple 
as tables and rows.

regards Max M