phpcr-odm
phpcr-odm copied to clipboard
Selecting nodes based on association doesn't work
According to the documentation this code should work to select a node based on an association:
$number = $dm->find('MyProject\Domain\Phonenumber', '/path/to/phone/number');
$user = $dm->getRepository('MyProject\Domain\User')->findOneBy(array('phone' => $number->getUuid()));
However, when using this code to get a MenuNode
documentation with a specific content object, I get an error:
The code
$dm = $this->get('doctrine_phpcr')->getManager();
$contentUuid = $dm->getPhpcrSession()->getItem('/cms/content/home')->getPropertyValue('jcr:uuid');
$dm->getRepository(MenuNode::class)->findOneBy(['content' => $contentUuid]);
The error
Cannot use association property "content" of class "...\MenuNode" as a dynamic operand
The docs seem to be incorrect.
More importantly, I can't find a way to select the node. The QueryBuilder can't help with this either.
it looks like we added some sanity check in the query builder that is not really right. semantically that code looks wrong, it should be 'content' => $content and the query builder should extract the uuid for $content. but i guess that does not work either.
functional tests for the query builder look rather limited, i think we have this situation not covered (we should at least have one that expects this exception)
@dantleech do you remember anything about this? did we just stop at that point, or is there a reason why this would not work?
oh, one thing: who is the owning side? i think searching by referrer would be difficult. searching for a field referencing something else should be possible.
As far as I know, if the User is the owner (i.e. it has a PHPCR property called phone
) then this should work.
The MenuNode
class here is the one from the CmfMenuBundle. I guess it's owner: https://github.com/symfony-cmf/MenuBundle/blob/master/Resources/config/doctrine-model/MenuNode.phpcr.xml#L16
https://github.com/symfony-cmf/MenuBundle/pull/241 looks right but seems not to work. wouter, can you maybe try to write a failing functional test here in phpcr-odm for this that shows the problem?