1

我对教义 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. 

请问有没有办法查询这种属性?

4

1 回答 1

0

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

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

在 ContainerAware 上下文(控制器或夹具)中:

/** @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');
于 2015-09-07T08:58:23.093 回答