Search code examples
phppropelsoft-delete

Does Propel know when an object has been soft-deleted, so that child entities could still show their deleted parent?


I am soft-deleting objects in a MySQL database and using the Propel ORM. I have gotten soft-deleting to work, but at the cost of losing my enforced parent-child relationships, since the actual rows are not being deleted.

Is there any way for Propel to know that a record has been soft-deleted when you access it, so that a null-reference exception is not thrown? This way, although a parent has been deleted, its child can still read it's relation, but when updating a child, or creating a new child, the deleted parent is not accessible.

For example,

Book has an AuthorId, and if the author belonging to AuthorId is soft-deleted, then:

$book->getAuthor();

would return the correct author (for viewing purposes only). However, if a new book was added, the author that was soft-deleted is not available to be selected.

Does anybody know if that functionality is built into Propel?


Solution

  • Soft delete is a broken abstraction. You should use the archivable behavior instead (see why in the Propel blog: http://propelorm.org/blog/2011/08/29/introducing-archivable-behavior-and-why-soft-delete-is-deprecated.html)