Closed abirhoss closed 4 years ago
@Abir-H thanks for the idea! Right now there is no way to specify the flag globally however you may have some luck with an event listener that will disable exceptions for all not found documents.
Thinking about this I'm not entirely sure how we'd go on about this: when the hydrator encounters a reference, it creates a proxy object and injects that into the mapped property. The proxy object is then initialised when a method call is made on the proxy object. However, at that time it's too late to generically handle the missing proxy: we can't return null
and also shouldn't return an uninitialised object.
Looking at the PR where we introduced this behaviour (#1336), there's a comment that explains the problem in detail: https://github.com/doctrine/mongodb-odm/pull/1336#issuecomment-342582157.
I'll see if we can come up with a way to allow to change this in the mapping, but I'm not sure it's possible. One thing we need to do either way is to show an example in the cookbook about how to properly handle this event and deal with a missing proxy object.
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.
Closing here as there is currently no feasible way to handle this (see comment linked above). I'm not sure if I want to expose handling this kind of behaviour in the mapping.
Feature Request
Summary
When mongo references become invalid, doctrine throws the
DocumentNotFoundException
from doctrine mongo-odmCaught exception: The "MongoDBODMProxies\__CG__\CrLib\Document\Image" document with identifier "0e2922a9-7dcd-4709-ad8e-9d36cd98f11d" could not be found.
on every document that has that now invalid reference. There is a way to disable this exception by setting$eventArgs->disableException();
in thedocumentNotFound
function (mongodb-odm/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php
). The original function is shown belowIs there a way we can enable the
disableException
flag forDocumentNotFoundEventArgs
through a config setting or handle DocumentNotFoundExceptions more gracefully? We dont want to put try catch blocks every where