[odb-users] Best Practice deleting persistent objects

Boris Kolpackov boris at codesynthesis.com
Thu Apr 3 13:39:48 EDT 2014


Hi Per,

Per Edin <info at peredin.com> writes:

> I would advice against ON DELETE CASCADE in this particular case
> though. 1. It can lead to real headaches if someone removes a group by
> mistake, either by removing a group from within C++ code or by an
> accidental DELETE FROM group WHERE... the cascade doesn't give any
> warnings at all.

I agree, ON DELETE can bring trouble. And, IMO, the biggest issue
is that there is no automatic way to synchronize objects that were
loaded into memory with the database state once ON DELETE has done
its job.

But it seems people like this functionality and I think for certain
kind of workflows it can work, if one is careful.


> 2. Removing a group doesn't necessarily mean the users shall be
> removed, since a user can be in 0 groups or already is a member
> of other groups.

Well, this one you can solve by using on_delete(set_null) instead
of cascade.

Boris



More information about the odb-users mailing list