phpcr-odm icon indicating copy to clipboard operation
phpcr-odm copied to clipboard

figure out how to handle dangling weak/path ReferenceOne/Many properties

Open dbu opened this issue 11 years ago • 4 comments

this is a follow-up of #116

the problem is: what happens when a ReferenceOne path or weak reference property points to something non-existing? is the property null? is the currently invalid reference removed on save or kept (which would make sense, in case the node at path appears later). but if it is usually kept, how can we delete it if we want?

dbu avatar Feb 28 '14 15:02 dbu

I think, that the invalid reference should stay intact, but ODM should simply return null. (So basically the way it's handled in 1.0.1). If something is being deleted without proper cleanup, the chance is, that it's a bug/mistake. In that way, when WeakReferences are preserved, mistakenly deleted nodes can be restored from backup (eg. by Toromiro or other JCR tool) and previously broken references will be valid again.

The other thing to consider - is it possible to do some sort of optional cleanup, when deleting a node? Eg. I want to delete a node with image file, so ODM provides a simple way to null out all refering fields..

eXsio avatar Mar 31 '14 13:03 eXsio

i think i never tested, but so you tested that if you change a document that has a weak reference / path reference to nonexisting, but you don't touch the reference field, it stays intact? that would be very good news, i was afraid it might lose the info. if its really preserved, this issue is actually a documentation issue and not something that needs a fix in code...

you can configure cascade delete on reference / referrer mappings for the cleanup.

dbu avatar Mar 31 '14 15:03 dbu

Yes, I'm using ODM 1.0.1 and if I remove a node, which is referenced by another node, ODM (or Jackalope - I'm not sure on what level it's being done) returns null, but the reference field in JCR (I'm using Jackrabbit) is intact. Considering that's a pretty important thing, it should be heavily tested, both with Jackrabbit and DBAL implementation. I can't guarantee that I'll be able to provide tests for this though (primarily due to the lack of free time:/ )...

eXsio avatar Mar 31 '14 16:03 eXsio

thanks for the report. i will try to add some tests around this in the near future, so we at least know what works and what not.

dbu avatar Mar 31 '14 18:03 dbu