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

How to query doctrine odm class' multivalue field? #200

Closed
lowki opened this issue May 5, 2015 · 16 comments
Closed

How to query doctrine odm class' multivalue field? #200

lowki opened this issue May 5, 2015 · 16 comments

Comments

@lowki
Copy link

lowki commented May 5, 2015

My document class, contains multivalue fields, how can I query them with the query builder? I've tried like() and fullTextSearch() methods, but both failed.
I found that the generated query specifies the first index for the value array.

EXTRACTVALUE(n0.props, '//sv:property[@sv:name="style"]/sv:value[1]') = 2)
@dantleech
Copy link
Contributor

->eq()->field('foo')->literal('bar') should do it?

@lowki
Copy link
Author

lowki commented May 6, 2015

This is exactly what i do.

@dantleech
Copy link
Contributor

Can you check which version of jackalope doctrine-dbal you are using?

$ composer show --installed | grep jackalope

The following JCR-SQL2 query works for me locally:

PHPCRSH> SELECT * FROM [nt:unstructured] WHERE multivalue_field = 'any of the values will match this';

@lowki
Copy link
Author

lowki commented May 6, 2015

I'm using jackalope 1.0.1 and jackalope-doctrine-dbal 1.0.0
Should I update?

@dantleech
Copy link
Contributor

I think your issue is probably fixed by this PR: jackalope/jackalope-doctrine-dbal#243

I think this is only available in the recent 1.2 release.

@lowki
Copy link
Author

lowki commented May 12, 2015

Ok, juste updated to jackalope 1.2 and problem still there.

Here the querybuilder code :

$qb->andWhere()->orX()->like()->field("p.style")->literal(2);

And the MySQL query generated :

    SELECT n0.path AS n0_path, n0.identifier AS n0_identifier, n0.props AS n0_props FROM phpcr_nodes n0 WHERE n0.workspace_name = 'default' AND n0.type IN ('nt:unstructured', 'rep:root') AND ((0 != FIND_IN_SET("2", REPLACE(EXTRACTVALUE(n0.props, '//sv:property[@sv:name="type"]/sv:value'), " ", ",")) AND CAST(EXTRACTVALUE(n0.props, '//sv:property[@sv:name="style"]/sv:value[1]') AS DECIMAL) LIKE 2) AND (EXTRACTVALUE(n0.props, 'count(//sv:property[@sv:name="phpcr:class"]/sv:value[text()="Detours\\MainBundle\\Document\\Product"]) > 0') OR EXTRACTVALUE(n0.props, 'count(//sv:property[@sv:name="phpcr:classparents"]/sv:value[text()="Detours\\MainBundle\\Document\\Product"]) > 0'))) ORDER BY CAST(EXTRACTVALUE(n0.numerical_props, '//sv:property[@sv:name="phpcr_locale:en-villaPackage"]/sv:value[1]') AS DECIMAL) ASC, EXTRACTVALUE(n0.props, '//sv:property[@sv:name="phpcr_locale:en-villaPackage"]/sv:value[1]') ASC

@dbu
Copy link
Member

dbu commented Aug 10, 2015

ping @dantleech

@dantleech
Copy link
Contributor

@lowki could you try the query in the PHPCR shell, this works for me using jackalope:

PHPCRSH> ls
/cmf/stanton/contents/foo [nt:unstructured] > nt:base
+-----------------+--------------+-----------------+
| jcr:primaryType | NAME (15)    | nt:unstructured |
| numbers         | LONG (1,1,1) | [0] 5           |
|                 |              | [1] 3           |
|                 |              | [2] 1           |
+-----------------+--------------+-----------------+
1 nodes in set (0.001381 sec)
PHPCRSH > select * from [nt:unstructured] where numbers = 3;
// returns the correct result

@dbu
Copy link
Member

dbu commented Aug 24, 2015

ping @lowki

@lowki
Copy link
Author

lowki commented Aug 25, 2015

Thank you @dantleech, I didn't know there is such a tool, I will give it a try.

@dantleech
Copy link
Contributor

fyi, it would probably be best to install it as a dependency:

http://phpcr.readthedocs.org/en/latest/phpcr-shell/installation.html#install-as-an-embedded-application

if you are using Symfony then you can probably start it with ./app/console doctrine:phpcr:shell

Otherwise you can start it manually, e.g.

$ ./vendor/bin/phpcrsh --transport=doctrine-dbal --db-name=... --db-password=... --db-driver=pdo_mysql

@dantleech
Copy link
Contributor

fyi, it would probably be best to install it as a dependency, as this means that you will be using the same lobrary versions as your application:

http://phpcr.readthedocs.org/en/latest/phpcr-shell/installation.html#install-as-an-embedded-application

if you are using Symfony then you can probably start it with ./app/console doctrine:phpcr:shell

Otherwise you can start it manually, e.g.

$ ./vendor/bin/phpcrsh --transport=doctrine-dbal --db-name=... --db-password=... --db-driver=pdo_mysql

@dbu dbu closed this as completed Aug 25, 2015
@dantleech
Copy link
Contributor

Reopened as I don't think this has been resolved.

@dantleech dantleech reopened this Aug 25, 2015
@dbu
Copy link
Member

dbu commented Sep 21, 2015

@dantleech can you update the description or open a new issue that explains what needs to be fixed? i understood that a newer version of jackalope solved the problem

@dantleech
Copy link
Contributor

Well, I can't reproduce it. @lowki did you have any luck with installing PHPCR shell as a dep? Did my query work for you? Does your query work as you expected?

@dbu
Copy link
Member

dbu commented Sep 29, 2015

ping @lowki

@dbu dbu closed this as completed Mar 29, 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