[DDC-3108] Criteria cannot reference a joined tables' fields when used with an ORM QueryBuilder Created: 30/Apr/14  Updated: 30/Apr/14

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL, ORM
Affects Version/s: 2.4.2
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Chris Rog Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: criteria, dql, orm, querybuilder


 Description   

This regression was introduced in 2.4.2 with the addition of the "rootAlias" stuff. Basically, the hard-coded addition of the rootAlias + "." prevents any Criteria object from referencing any field that isn't on the first table selected.

Example:
// Assume $repo is a valid EntityRepository and $value is some scalar value.
$qb = $repo->createQueryBuilder('T1')->join('T1.field', 'T2');

$criteria = new Comparison('T2.field2', Comparison::EQ, $value);

$qb->addCriteria($criteria);
$dql = $qb->getDQL();

$dql is now (roughly) equal to:
SELECT T1 FROM <entityclass> T1 JOIN T1.field T2 WHERE T1.T2.field2 = <value>

Evaluating this causes QueryExceptions to be thrown; usually something along the lines of "Expected Doctrine\ORM\Query\Lexer::<token>, got '.'"

There's a similar issue involving ordering by a related field for the same reason.






[DDC-3034] QueryBuilder invalid number of bound params Created: 17/Mar/14  Updated: 17/Mar/14  Resolved: 17/Mar/14

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4.2
Fix Version/s: None
Security Level: All

Type: Bug Priority: Minor
Reporter: Mike Zukowsky Assignee: Marco Pivetta
Resolution: Invalid Votes: 0
Labels: orm, querybuilder
Environment:

PHP 5.4.16, Zend Framework 2.2.5, Doctrine ORM Module 0.8.0



 Description   
    /**
     * @param int  $companyId
     * @param bool $includeDeleted
     * @return \Doctrine\ORM\QueryBuilder
     */
    public function findCompanySubjects($companyId, $includeDeleted = false)
    {
        $qb=$this->createQueryBuilder('t')
            ->addSelect('owner')
            ->innerJoin('t.owner', 'owner')
            ->innerJoin('owner.company', 'company')
            ->andWhere('t.deleted = :deleted')
            ->andWhere('company.id = :id')
            ->orderBy('t.name', 'asc')

            ->setParameter('deleted', $includeDeleted)
            ->setParameter('id', $companyId)
        ;

        return $qb;
    }

Code above does not work for me. I'm still getting an error "Invalid parameter number: number of bound variables does not match number of tokens". However, bound parameters does work with raw DQL and the Query object.



 Comments   
Comment by Marco Pivetta [ 17/Mar/14 ]

Mike Zukowsky what is the complete DQL that is produced for that query? And does it work with a DQL query written directly (rather than the QB)?

Comment by Mike Zukowsky [ 17/Mar/14 ]

Raw DQL is:

SELECT t, owner FROM Domain\Entity\Subject t INNER JOIN t.owner owner INNER JOIN owner.company company WHERE t.deleted = :deleted AND company.id = :id ORDER BY t.name asc

And yes, it does work with a DQL query written directly:

        // $qb from above

        $query=$qb->getQuery()->setParameters(array(
            'deleted' => $includeDeleted,
            'id'      => $companyId
        ));

        debug($query->getArrayResult()); // returns a list of subjects
Comment by Marco Pivetta [ 17/Mar/14 ]

You are returning the QB in your reported code - I'm pretty sure that some interaction with it is going on at a later point in time.

Could you provide the code that is causing the problem? Otherwise, this doesn't look like a bug to me.





[DDC-2923] Query expressions ALL/ANY/SOME don't seem to work Created: 17/Jan/14  Updated: 09/Feb/14  Resolved: 09/Feb/14

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: DQL, ORM
Affects Version/s: 2.3.4
Fix Version/s: None
Security Level: All

Type: Bug Priority: Critical
Reporter: Kees Schepers Assignee: Benjamin Eberlei
Resolution: Invalid Votes: 0
Labels: dql, orm, querybuilder
Environment:

Doctrine 2.3 from a Symfony 2.4 application running on a Ubuntu 12.04 machine onder Apache / PHP.



 Description   

It seems that the query expressions ALL() / ANY() / SOME() don't work (anymore). See my testcase and the error on my stackoverflow question:

http://stackoverflow.com/questions/21184374/doctrine-any-all-some-doesnt-work

The exception is thrown in the Query/Parser.php (line: 3040) since the functions are not mapped in the parser class as string functions.

What goes wrong?



 Comments   
Comment by Marco Pivetta [ 20/Jan/14 ]

Tests seem to cover this use case at https://github.com/doctrine/doctrine2/blob/a83f5df47c463cd64a2525274c97812e04a8eca5/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php#L418-L426 - try using plain DQL instead of the query builder first - may be a problem with the QB

Comment by Steve M├╝ller [ 20/Jan/14 ]

Kees Schepers You use the expression wrong. ALL/ANY/SOME expression needs another expression to compare against. Something like:

SELECT * FROM foo WHERE ALL(SELECT bar.id FROM bar WHERE bar.id > 100)

is not valid SQL.

What you want is something like:

SELECT * FROM foo WHERE foo.id > ALL(SELECT bar.id FROM bar WHERE bar.id > 100)

I hope you get what I mean, I don't know exactly what you supposed your query to do but I hope you get the point. This is not a Doctrine bug.

See here for an example with the query builder: https://github.com/doctrine/doctrine2/blob/a83f5df47c463cd64a2525274c97812e04a8eca5/tests/Doctrine/Tests/ORM/QueryBuilderTest.php#L716-L729

Comment by Benjamin Eberlei [ 09/Feb/14 ]

Not an issue, the `andWhere($expr->all())` usage is wrong.





[DDC-2322] [GH-592] Added ability to specify INDEX BY when creating a QueryBuilder from a Repository Created: 27/Feb/13  Updated: 01/May/14  Resolved: 12/Mar/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.2, 2.3, Git Master
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Invalid Votes: 0
Labels: QueryBuilder, Repository


 Description   

This issue is created automatically through a Github pull request on behalf of cmenning:

Url: https://github.com/doctrine/doctrine2/pull/592

Message:

This is a handy shortcut when using indexed results.



 Comments   
Comment by Benjamin Eberlei [ 12/Mar/13 ]

A related Github Pull-Request [GH-592] was closed
https://github.com/doctrine/doctrine2/pull/592

Comment by Craig Menning [ 12/Mar/13 ]

I disagree with the reasoning behind closing this request. In DoctrineBundle,

getDoctrine()->getEntityManager()

has been deprecated, which leaves you to use

getDoctrine()->getRepository($class)->createQueryBuilder();

Adding ->from() at that point is redundant since it's already been specified inside the createQueryBuilder() call. It seems wasteful to not allow a passthru of the $indexBy argument during the initial call when it's already supported by the from() called inside createQueryBuilder().

Comment by Marco Pivetta [ 12/Mar/13 ]

The repository is already (probably) doing too much. A simpler approach with:

$qb = $em->createQueryBuilder()->select('e')->from($repo->getClassName(), 'e', 'e.stuff')

Is no big deal in my opinion.

Comment by Doctrine Bot [ 01/May/14 ]

A related Github Pull-Request [GH-592] was closed:
https://github.com/doctrine/dbal/pull/592





[DDC-2140] [GH-512] Added addParameters() to Query and QueryBuilder Created: 13/Nov/12  Updated: 08/Feb/14

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3, Git Master
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: Query,, QueryBuilder
Environment:

OS X 10.8.2, PHP 5.3.18, Nginx 1.2.4 (php through FPM)



 Description   

This issue is created automatically through a Github pull request on behalf of jappie:

Url: https://github.com/doctrine/doctrine2/pull/512

Message:

This method behaves like setParameters() before version 2.3:
It will add new parameters to the collection, and override any existing positions/names.

It can take a Doctrine\Common\Collections\ArrayCollection with Doctrine\ORM\Query\Parameter objects, as well as a plain array with key/value pairs, as argument.

This will greatly ease the upgrade to Doctrine 2.3, because you only need to perform a project-wide replace of setParameters with addParameters, in stead of going into your code and determine if calls to setParameters are ok or need refactoring.

I've also added unit-tests to maintain integrity.



 Comments   
Comment by Benjamin Eberlei [ 20/Nov/12 ]

A related Github Pull-Request [GH-512] was closed
https://github.com/doctrine/doctrine2/pull/512

Comment by Jasper N. Brouwer [ 20/Nov/12 ]

I don't feel strong need to have such an API.
If you want to keep track and merge collection of parameters, all you have to do is create an array (or an ArrayCollection), manipulate the instance and then setParameters at the end.
Unless you give me a stronger argument, this code won't be in. Closing for now.

Hi Guilherme,

I agree that such a method makes less sense in Query, because when you write a DQL string all parameters are known at once. But when using the QueryBuilder you might need different parameters in different cases, so addParameters() becomes useful there.

I guess it's just a convenience method, like IMHO setParameter() is. (You could just do $qb->getParameters()->add())

The main reason for adding the method was, like I said, upgrading to Doctrine 2.3. I've already upgraded all my projects to Doctrine 2.3, so the method is less useful for me now. But it took me a full day to refactor my repositories, because there is no safe way to automate the process. A simple search-and-replace setParameters() to addParameters() would have taken me 5 minutes

I'm content with your decision.
If others find addParameters() useful, I hope they let us know.

Comment by Doctrine Bot [ 08/Feb/14 ]

A related Github Pull-Request [GH-512] was closed:
https://github.com/doctrine/dbal/pull/512





Generated at Fri Aug 29 01:15:03 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.