Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting nodes based on association doesn't work #682

Open
wouterj opened this issue Dec 31, 2015 · 5 comments
Open

Selecting nodes based on association doesn't work #682

wouterj opened this issue Dec 31, 2015 · 5 comments

Comments

@wouterj
Copy link
Contributor

wouterj commented Dec 31, 2015

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.

@dbu
Copy link
Member

dbu commented Jan 4, 2016

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
Copy link
Member

dbu commented Jan 4, 2016

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.

@dantleech
Copy link
Contributor

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

@wouterj
Copy link
Contributor Author

wouterj commented Jan 7, 2016

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

@dbu
Copy link
Member

dbu commented Jan 9, 2016

symfony-cmf/menu-bundle#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?

wouterj added a commit to wouterj/phpcr-odm that referenced this issue Jan 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants