phpcr-odm icon indicating copy to clipboard operation
phpcr-odm copied to clipboard

Selecting nodes based on association doesn't work

Open wouterj opened this issue 9 years ago • 5 comments

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.

wouterj avatar Dec 31 '15 12:12 wouterj

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?

dbu avatar Jan 04 '16 09:01 dbu

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.

dbu avatar Jan 04 '16 09:01 dbu

As far as I know, if the User is the owner (i.e. it has a PHPCR property called phone) then this should work.

dantleech avatar Jan 04 '16 10:01 dantleech

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

wouterj avatar Jan 07 '16 10:01 wouterj

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?

dbu avatar Jan 09 '16 11:01 dbu