Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.2.0
-
Fix Version/s: None
-
Component/s: Relations
-
Labels:None
Description
Doctrine's cloning feature is based on the Doctrine_Record::copy($deep = false) method, while the $deep param says whether to clone the related objects as well, or not.
However, considering the perspective of the application logic, the functional need can also be stated as: "I wish you to clone yourself, expecting you to know yourself which related objects you need to clone as well, or even to de-reference, or whatever is needed (e.g. to remove the relation)."
For this, the $deep argument is somehow inaccurate, as it does not take into consideration the different meanings of the relations:
- some relations (namely aggregations in UML terminology) need that the cloned object shall still refer to the same object (like referenced by the cloned object)
- some relations (namely compositions) need to clone the related objects as well, as the latter are owned by the main object.
Practical example: when cloning an invoice (Doctrine_Record), application logic expects that its invoice line items be cloned as well (compositions), but not the reference to the customer (cloning my customers this way will not increase my business
.
Thus it would be great if there were a means to specify the needed behaviour in the schema.yml etc.
Thinkable approach: extend the "application-level cascade" feature of Doctrine by adding a "clone" or "copy" parameters. Then the copy() method in Doctrine_Record will know which related objects to clone as well, or not, or to clear (null). I guess it's quite analogous to the "delete" cascade stuff.
So far my proposal. In case it will find support, I will then be happy to provide an implementation proposal.