I have a MongoDBException:
"Invalid find by call Bundle\Document\Property::$fieldName (criteriaWith)".
I don't understand what is wrong here. Can someone help me please?
Here's the Stack Trace:
1 . in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/MongoDBException.php
at line 38
public static function invalidFindByCall($documentName, $fieldName, $method) {
return new self(sprintf('Invalid find by call %s::$fieldName (%s)', $documentName, $fieldName, $method));
}
- at
MongoDBException ::invalidFindByCall ('\Bundle\Document\Property', 'criteriaWith', 'findByCriteriaWith')
in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentRepository.php
at line 222
if ($this->class->hasField($fieldName)) {
return $this->$method(array($fieldName => $arguments[0]));
} else {
throw MongoDBException::invalidFindByCall($this->documentName, $fieldName, $method . $by);
}
at
DocumentRepository ->__call ('findByCriteriaWith', array(array('name' => 'ho')))
insrc/Bundle/Controller/PropertyController.php
at line 286else { criteria['name'] = $name; $entities = $repository->findByCriteriaWith($criteria); }
The Log Messages:
CRITICAL request Uncaught PHP Exception Doctrine\ODM\MongoDB\MongoDBException: "Invalid find by call Bundle\Document\Property::$fieldName (criteriaWith)" at vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/MongoDBException.php line 38 Context: { "exception": "Object(Doctrine\ODM\MongoDB\MongoDBException)" }
Let's go through ODM's document repository magic
__call
method (as that's what is called sincefindByCriteriaWith
does not exist) and highlight interesting parts.First we see
Your method name starts with "findBy" so we will enter this block leaving us later with
$method = 'findBy'
and$by = 'CriteriaWith'
Later on$by
gets camelized, as that's standard for field/property name, and leaves us with$fieldName = 'criteriaWith'
. Now next thing we see is$this->class->hasField($fieldName)
check which results in exception you got because your class does not have acriteriaWith
field.Summing up
$repository->findBySomething($value);
is equivalent to$repository->findBy(['something' => $value])
and throws exception if field does not exist in your doocument.