[PEAK] Cascading delete

Tiago Cogumbreiro cogumbreiro at gmail.com
Tue Jul 26 14:37:45 EDT 2005

> In fact, model attributes currently have an 'isComposite' attribute that
> indicates whether they are a composition link; i.e., items on the other
> side of the link are "owned" by the object.  This would probably be a good
> indication that removing the source object should result in removal of the
> target.  So, maybe something like this:
>      def remove(self,ob):
>          super(MyDM, self).remove(ob)
>          for feature in ob.mdl_features:
>              if feature.isComposite:
>                  if feature.isMany:
>                      items = feature.get(ob)
>                  else:
>                      items = [feature.get(ob)]
>                  for other in items:
>                      if other._p_jar is not None:
>                          other._p_jar.remove(other)
> This would cascade-delete all objects referenced by model attributes
> defined with 'isComposite = True' in their definition body.
Very nice indeed :) Thanks alot!

I only used teh events because it seemed to be the cleanest aproach to
the problem. I didn't knew that the model fields could be used in that
rather interesting technique.

On a side not, that example only works if you put the super.remove
call _after_ the propagation, otherwise when you get the mdl_features
attribute it will raise an error.

More information about the PEAK mailing list