I am new to Doctrine ODM and I am completely stuck in a simple query :(
Let me start with the structure of the document:
Array ( [_id] => 4ee1e4527f749c9411000012 [voteList] => Array ( [_id] => 4ee1e4527f749c9411000013 [votes] => Array ( ... stripped ... ) [latest] => Array ( [_id] => 4ee1e4527f749c9411000014 [rating] => 1 [voter] => Array ( [$ref] => Voter [$id] => 4ee1e4527f749c941100000f [$db] => x_test ) ) ) ... stripped ... )
This document is called Voting .
My question is: how to find voice documents by a specific voter (which is stored in the voteList.latest.voter element) .
I tried like this:
$builder ->field('voteList.latest.voter')->references($voter) ->getQuery() ->execute();
And this method also:
$result = $builder ->field('voteList.latest.voter.$id')->equals(new \MongoId($voter->getId())) ->getQuery() ->execute();
Both lead to this exception:
Doctrine\ODM\MongoDB\MongoDBException: No mapping found for field 'voteList.latest.voter' in class 'App\BaseBundle\Document\Voting'.
Am I creating a query incorrectly or is there something wrong with my document classes?
Thanks for reading, any advice is appreciated.
EDIT: attached documents
class Voting { protected $id; protected $voteList; public function __construct() { if ($this->voteList === null) { $this->voteList = new VoteList(); } } public function getId() { return $this->id; } public function getVoteList() { return $this->voteList; } } ; class VoteList implements \Countable, \ArrayAccess, \IteratorAggregate { protected $id; protected $votes = array(); protected $latest; public function getId() { return $this->id; } public function getLatest() { return $this->latest; } } class Vote { protected $id; public $voter; public function getId() { return $this->id; } public function getVoter() { return $this->voter; } public function setVoter(Voter $voter) { $this->voter = $voter; } }
source share