mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Improve Reverse Delete Rules

Open combscCode opened this issue 2 years ago • 2 comments

Fixes issues #2764 and #2308, implements lazy delete rules and delete rules on GenericReferenceFields.

To implement lazy delete rules: When delete rules are assigned to a Document that doesn't exist yet, I store them in a global dict. Whenever a new Document class is defined, it checks said global dict for any outstanding delete rules that it needs to assign on itself.

To implement delete rules on GenericReferenceFields: GenericReferenceField is now smart enough to register delete rules on many documents when its asked to. It does this by employing a helper class which provides a register_delete_rule function that actually can register delete rules on many documents, not just one. It exposes this class by defining a document_type property, which is kind of lying in a sense since this really is only intended to expose register_delete_rule and not handle any other functionality expected of document_type.

This is a little janky but I can't think of a way to do it "right" without changing which class is responsible for register_delete_rule and thus making a breaking change.

combscCode avatar Aug 04 '23 15:08 combscCode

mm i guess its not working : ) will come back to this later.

combscCode avatar Aug 04 '23 21:08 combscCode