1

I've got a problem with doctrine phpcr and the query builder. Is it possible to do a query on an attribute with ReferenceOne() ?

e.g :

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

But when I'm trying to build a query on it :

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

I've got the following error

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

Is there a way to do a query on this kind of attribute please ?

Peekmo
  • 2,843
  • 2
  • 19
  • 25

1 Answers1

0

You need to use the DocumentManager::getReferrers() to do that.

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

In a ContainerAware context (Controller or Fixture) :

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

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

Here it would be :

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