Doctrine ODM/MongoDB:如何查询嵌入文档中的引用?

Doctrine ODM/MongoDB:如何查询嵌入文档中的引用?,mongodb,doctrine,symfony,doctrine-orm,doctrine-odm,Mongodb,Doctrine,Symfony,Doctrine Orm,Doctrine Odm,我不熟悉Doctrine ODM,我完全被一个简单的查询所困扰:( 让我从文档结构开始: Array ( [_id] => 4ee1e4527f749c9411000012 [voteList] => Array ( [_id] => 4ee1e4527f749c9411000013 [votes] => Array ( ... stripped ...

我不熟悉Doctrine ODM,我完全被一个简单的查询所困扰:(

让我从文档结构开始:

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 ...
)
此文档称为投票

我的问题是,如何查找特定投票人的投票文档(存储在voteList.latest.voter中)

我这样试过:

$builder
    ->field('voteList.latest.voter')->references($voter)
    ->getQuery()
    ->execute();
这样也可以:

$result = $builder
    ->field('voteList.latest.voter.$id')->equals(new \MongoId($voter->getId()))
    ->getQuery()
    ->execute();
两者都导致了这一例外:

Doctrine\ODM\MongoDB\MongoDBException: No mapping found for field 'voteList.latest.voter' in class 'App\BaseBundle\Document\Voting'.
我是否生成了错误的查询,或者我的文档类可能有问题?

感谢您的阅读,任何建议都将不胜感激

编辑:附件

    /**
     * @ODM\Document(repositoryClass="App\BaseBundle\Document\VotingRepository")
     */
    class Voting
    {
        /**
         * @ODM\Id
         * @var int
         */
        protected $id;

        /**
         * @ODM\EmbedOne(targetDocument="App\BaseBundle\Document\VoteList")
         * @var VoteList
         */
        protected $voteList;

        public function __construct()
        {
            if ($this->voteList === null) {
                $this->voteList = new VoteList();
            }
        }

        /**
         * @return string
         */
        public function getId()
        {
            return $this->id;
        }

        /**
         * @return VoteList
         */
        public function getVoteList()
        {
            return $this->voteList;
        }
    }
    ;

    /**
     * @ODM\EmbeddedDocument
     */
    class VoteList implements \Countable, \ArrayAccess, \IteratorAggregate
    {
        /**
         * @ODM\Id
         */
        protected $id;

        /**
         * @ODM\EmbedMany(targetDocument="App\BaseBundle\Document\Vote")
         * @var Vote[]
         */
        protected $votes = array();

        /**
         * @ODM\EmbedOne(targetDocument="App\BaseBundle\Document\Vote")
         * @var Vote
         */
        protected $latest;

        public function getId()
        {
            return $this->id;
        }

        /**
         * @return Vote
         */
        public function getLatest()
        {
            return $this->latest;
        }
    }

    /**
     * @ODM\EmbeddedDocument
     */
    class Vote
    {
        /**
         * @ODM\Id
         */
        protected $id;

        /**
         * @ODM\ReferenceOne(targetDocument="App\BaseBundle\Document\Voter")
         * @var Voter
         */
        public $voter;

        public function getId()
        {
            return $this->id;
        }

        public function getVoter()
        {
            return $this->voter;
        }

        public function setVoter(Voter $voter)
        {
            $this->voter = $voter;
        }
    }

我发现它不工作是因为一个odm错误


您应该发布这两个文档的代码,让我们更完整地了解情况。@elnur感谢您的评论。编辑:添加的文档,简化为引用/嵌入内容看起来现在已经解决了链接的问题似乎没有直接解决OP的问题,而问题在最新版本中仍然存在。实际其实,除了一个项目之外,我已经放弃了使用doctrine ODM。与ORM的方式相反,测试版太多了,我不认为它会很快达到真正稳定的状态。