How to suppress a MongoDDException when proxy can't find a referenced document
Posted
by
Madarco
on Stack Overflow
See other posts from Stack Overflow
or by Madarco
Published on 2012-06-14T08:24:53Z
Indexed on
2013/06/28
16:22 UTC
Read the original article
Hit count: 144
doctrine-odm
We are using Symfony2/DoctrineOdm/MongoDB and when we do:
if ($doc.referenceOne != null) { ... }
and the $doc.referenceOne
contains a MongoDbRef that point to a deleted/lost document, the Doctrine Proxy object raises a MongoDBException.
It is possible to tell the Proxy return null instead of raising the exception?
Detailed Explanation:
Our document:
class User {
/* @MongoDB\ReferenceOne( ... ) */
private $photo;
}
If $photo contains a MongoDbRef, but the document is lost/deleted,
when we do if ($user.photo) { ... }
doctrine will raise a MongoDBException:
The "Proxies\DocumentPhotoProxy" document with identifier "4fd8b3ef732bafab7b000000" could not be found
We want to suppress the exception since our application can handle null values in that variable.
(we could simply log that error, while the exception propagate to a 500 page and disrupt our service)
© Stack Overflow or respective owner