-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
DDC-3635: QueryBuilder - INSTANCE OF with parameter not working #4462
Comments
Comment created by @guilhermeblanco: INSTANCE OF expressions expect either their class names or their corresponding class metadata. This means the following examples are valid:
Assigning class name directly does not work. |
Comment created by @Ocramius: Re-opening. I think this is a documentation issue then, as http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#id2 says that the |
Comment created by @guilhermeblanco: [~ocramius] And it does. However, the bound parameter must be a ClassMetadata. |
It seams that there is a similar issue on the DoctrineORMAdapter object. $query = $this->createQueryBuilder('o')
->leftJoin('o.child', 'c')
->where('c INSTANCE OF :class')
->setParameter('class', $em->getClassMetadata('My\Entity\Class'))
->getQuery();
$adapter = new DoctrineORMAdapter($query);
... This main query is okay : the mapping on the discriminator is done with the discriminator value. However, the subquery create to get the count isn't abble to do the job : the mapping is done with the string 'My\Entity\Class' and not the discriminator value. |
Does not work for me @jycamier. I had to put the class name in the parameter. Tried $em->getClassMetadata() no luck. Then played around with it and it works on the class name without the namespace, which is weird. Hey it works :). |
Issue from 24 Mar 2015, is it still relevant? @guilhermeblanco maybe you know? :-) |
@smilesrg would require a test - fairly sure it still doesn't work, since DQL was not refactored in that area. |
Still does not work. :( Wasn't an issue as we simply had to do the instance check on the result set. Issue now is that the result set has become larger and there will be a performance issue. I had initially thought that the classname worked. But it did not. Will do some more research and post findings. |
Jira issue originally created by user Wilt:
I use single table class inheritance.
When I write my *INSTANCE OF* clause in my QueryBuilder like this:
It does not work correctly. The problem seems to lie in the fact that the parameter is bound to the SQL query. So if I change the entity_class to the discriminator column name it works correctly.
So if the discriminator value for *My\Entity\Class* would be discriminator then this does work:
So the step for getting the discriminator column from the class name is missing and instead the class name is bound to the MySql query directly.
The text was updated successfully, but these errors were encountered: