I have a situation where when a record is deleted if its parent has no
other child records it should also be deleted, and either both deletes
are successful or should be discarded.
I thought about achieving this by using the records
bizobj.beforeDelete() method. The idea is:

beforeDelete()
    parentPK = self.getParentPK()
    cr=getTempCursor()
    cr.execute("select count(child_id) as n_child form child_table
where parent_id = ?", (parentPk,))
    ds = cr.getDataSet()
    if ds[0]['n_child'] == 1:
        self._parentPkToDelete = parentPK

    return ""

Then in bizobj.afterDelete() we just check if there is a
self._parentPkToDelete and delete the parent record.

However, from the code I see that both beforeDelete() and
afterDelete() are not encapsulated within the same transaction as the
delete() method. So I wonder what would be a safer / safer approach. I
though about two alternatives:
* wrapping everything in my own transaction in a custom myDelete() method.
* checking first if the parent only has one child and, if this is
true, delete the parent (cascading delete would take care safely of
the rest).

I suppose this is a common situation. Any thoughts, pointers?
Txs,
Miguel


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to