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

[DDC-3609] Syntax error in class table inheritance join when WITH is used in DQL query #1328

Open
wants to merge 3 commits into
base: old-prototype-3.x
Choose a base branch
from

Conversation

adeanzan
Copy link

I've added a test case to reproduce this issue. It's a bit contrived, but hopefully gives you enough to go on.

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3610

We use Jira to track the state of pull requests and the versions they got
included in.

LEFT JOIN ComplexOrder.deliveryLocations ComplexDeliveryLocation

WHERE
(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you simplify the query to the minimal example making it crash?

@adeanzan
Copy link
Author

adeanzan commented Apr 3, 2015

@Ocramius - I believe this is the simplest query, the unusual behavior only appears when joining multiple tables that are used with class table inheritance.

Two consecutive "ON" statements appear in the generated query, which mysql and postgres both seem fine with, but sqlite does not handle.

@Ocramius
Copy link
Member

Ocramius commented Apr 3, 2015

@adeanzan I was wondering if it can be reproduced with a single entity joining on itself, for example

@adeanzan
Copy link
Author

@Ocramius - I appreciate you looking into this. I've added several more test cases and attempted to simplify them as much as possible to illustrate what's going on.

testCanFindSimpleOrderByBaseField - This is a very basic test that queries the base class on a field present in the base class. It is passing, as expected.

testCanFindSimpleOrderByChildField - This does a LEFT JOIN of a child class and queries on a property of the child class. This test case is failing and exhibits the problem in this issue. This is probably the simplest way to reproduce it, but I can look into your suggestion of joining an entity on itself if it would help.

testCanFindComplexOrder - Added for the sake of completeness, also fails for the same reason as the previous test case.

@sp-rhm
Copy link

sp-rhm commented Jul 20, 2015

I debugged this and added a possible fix in #1464. But I am not sure whether that fix is correct, and some of @adeanzan's Tests are still failing, albeit for a different reason now.

@mpdude
Copy link
Contributor

mpdude commented Sep 18, 2015

Could you please check if this is the same as http://www.doctrine-project.org/jira/browse/DDC-3697 and/or whether #1395 fixes it?

@mpdude
Copy link
Contributor

mpdude commented Sep 30, 2015

ping @adeanzan, your feedback would be helpful.

@adeanzan
Copy link
Author

@mpdude - The problem does sound similar, although the tests are still failing with the same problem.

I've just pushed some changes to make it compatible with your recent commit to disallow leading backslashes in FQCNs. I then ran the tests in your branch via:

$ curl https://raw.githubusercontent.com/doctrine/doctrine2/d85f44d07aa7c83baa7ecaf1d3583a98fce61901/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3609Test.php > tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3609Test.php
$ vendor/bin/phpunit --filter 'DDC3609Test::testCanFindSimpleOrderByChildField'

It looks like the same issue is still there since the generated query looks like:

SELECT d0_.id AS id_0, d0_.requester AS requester_1, d1_.fulfiller AS fulfiller_2, d0_.discr AS discr_3 FROM DDC3609Order d0_ LEFT JOIN DDC3609SimpleOrder d1_ ON d0_.id = d1_.id LEFT JOIN DDC3609ComplexOrder d2_ ON d0_.id = d2_.id LEFT JOIN DDC3609SimpleOrder d3_ INNER JOIN DDC3609Order d4_ ON d3_.id = d4_.id ON (d4_.id = d0_.id) WHERE d3_.fulfiller = 'FulfillerUser'

Thanks for looking into this and let me know if there's anything else I can do to assist.


FROM
Doctrine\Tests\ORM\Functional\Ticket\DDC3609Order BaseOrder
LEFT JOIN Doctrine\Tests\ORM\Functional\Ticket\DDC3609SimpleOrder SimpleOrder WITH SimpleOrder.id = BaseOrder.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this query is correct or makes sense. You probably want to do

"SELECT SimpleOrder
FROM ".__NAMESPACE__."\DDC3609SimpleOrder SimpleOrder 
WHERE SimpleOrder.fulfiller = 'FulfillerUser'"

here? That seems to work...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right for normal use, however testCanFindSimpleOrderByChildField and testCanFindComplexOrder were added to break down the failing query a bit more to help with debugging. The query in testIssue is the real use case.

To be clear, my goal is to get a result set of SimpleOrders and ComplexOrders where the fulfiller is 'FulfillerUser`. Since these objects both have the concept of a fulfiller (even though they store it via different relationships) I'd like to do this in a single query.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At that point probably someone else who knows Doctrine better than me should help. I don't know if what you're trying to do is possible at all.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I appreciate you looking into this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants