phpcr-odm
phpcr-odm copied to clipboard
provide migrating document class on DocumentManager too
there is now a command to migrate a document from one class to an other, but this would be useful functionality through code as well.
https://github.com/doctrine/phpcr-odm/blob/master/lib/Doctrine/ODM/PHPCR/Tools/Console/Command/DocumentMigrateClassCommand.php
I think also a more generic $dm->replace($fooDocument, $barDocument)
feature. This is valid behavior in PHPCR I think (when nodeType constraints are satisfied), so by extension I think maybe we should support it in ODM,
i agree. we had endless discussions in #262 about automatically merging / replacing documents.
for an explicit replace operation, there are already many options: either replace just the document itself but keep children of the old document, or only keep the new children (so if the new has no children, remove all old children), or merge children and take the new or the old child in case of a conflict (and then how to merge the children of children?).
when we flush a whole model tree, this is not explicit, and even more tricky. maybe we should say that then a replace can't happen, that it always has to be explicit...
Hmm. I think if you are going to remove the node and its children, then you may as well do $dm->remove($oldDoc); $dm->persist($newDoc)
. On the otherhand there is no clean way to replace / migrate a document at a specified path.
the problem with remove & persist new is that all children of the old document are removed as well. when this is intended, it can make sense to do this (though you noticed that it does not work in the same flush i think)