Doctrine PHPCR - 查询ReferenceOne属性

时间:2015-03-16 14:48:37

标签: doctrine-odm symfony-cmf doctrine-phpcr

我对doctrine phpcr和查询构建器有问题。是否可以使用ReferenceOne()?

对属性进行查询

例如:

/**
 * @PHPCR\ReferenceOne(targetDocument="....\Program")
 */
private $program;

但是,当我尝试在其上构建查询时:

$qb->where()->eq()->field('news.program')->literal($program->getId())->end();

我收到了以下错误

Cannot use association property "program" of class "...\News" as a dynamic operand. 

有没有办法对这种属性进行查询?

1 个答案:

答案 0 :(得分:0)

您需要使用 DocumentManager :: getReferrers()来执行此操作。

https://github.com/doctrine/phpcr-odm/blob/master/lib/Doctrine/ODM/PHPCR/DocumentManager.php#L722

在ContainerAware上下文(Controller或Fixture)中:

/** @var \Doctrine\ODM\PHPCR\DocumentManager $dm */
$dm = $this->getContainer()->get('doctrine_phpcr')->getManager();

$referrers = $dm->getReferrers($yourObject, null, null, null, 'YourBundle:ReferrersClass');

这将是:

$news = $dm->getReferrers($program, null, null, null, 'YourBundle:News');