Skip to content

Fix #1021 order by hidden eager loading#1022

Merged
soyuka merged 3 commits into
api-platform:2.0from
soyuka:hotfix/filter-eager-loading-order-by-hidden
Apr 1, 2017
Merged

Fix #1021 order by hidden eager loading#1022
soyuka merged 3 commits into
api-platform:2.0from
soyuka:hotfix/filter-eager-loading-order-by-hidden

Conversation

@soyuka

@soyuka soyuka commented Mar 30, 2017

Copy link
Copy Markdown
Member
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1021
License MIT
Doc PR na

@soyuka
soyuka force-pushed the hotfix/filter-eager-loading-order-by-hidden branch from 355bbf9 to f05370b Compare March 30, 2017 06:33
@soyuka
soyuka requested a review from teohhanhui March 30, 2017 06:46
@teohhanhui

Copy link
Copy Markdown
Contributor

I'm curious about GROUP BY and HAVING clauses too. We should add tests for them.

$wherePart = $queryBuilder->getDQLPart('where');

//reset parts
$queryBuilderClone->resetDQLPart('orderBy');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Logically the sequence should be: join - where - orderBy \o/

@soyuka

soyuka commented Mar 30, 2017

Copy link
Copy Markdown
Member Author

Your right, I'll add those in ~30min ;)

@soyuka
soyuka force-pushed the hotfix/filter-eager-loading-order-by-hidden branch 3 times, most recently from 2be6ab5 to 03b581c Compare March 30, 2017 09:43
@soyuka

soyuka commented Mar 30, 2017

Copy link
Copy Markdown
Member Author

W8 do not merge I'm adding a fix for #1023

INNER JOIN o_2.compositeLabel label_2
WHERE item_2.field1 = :foo
)
SQL;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

WDYT @teohhanhui ? A better fix would be to fix doctrine but this works fine as a temporary fix (will take a long time to get that fixed in doctrine :p). Indeed, it should be WHERE (o.item, o.label) IN (subquery).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe can you add a comment with this rationale? We'll remove this temporary when (if) the patch will be merged in Doctrine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't even know there's such a syntax in SQL. Obviously I don't really use composite keys 😛

Anyway, I think this is fine.

@teohhanhui teohhanhui Apr 3, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, but I think the tests are confusing, because there seems to be no eager loading going on (how do we tell?). If so, we can skip query rewriting in such cases, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The fix will get applied only if the conditions are a match (where clause + eager + composite identifier in this case). There will be no rewriting if those conditions don't match.
I force those conditions with the test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What I mean is that even though $forceEager is true, the query itself might not need to be rewritten if there is no eager loading going on, no? (Not specific to this test case.)

@soyuka soyuka Apr 3, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Eager loading is active when there are joins, this condition checks that. The rewrite is needed only when there is a where clause.

@dunglas

dunglas commented Apr 1, 2017

Copy link
Copy Markdown
Member

Feel free to merge this one @soyuka. I'll tag a new patch release after that.

@soyuka
soyuka force-pushed the hotfix/filter-eager-loading-order-by-hidden branch from ee14560 to 8ba69e3 Compare April 1, 2017 07:09
@soyuka
soyuka force-pushed the hotfix/filter-eager-loading-order-by-hidden branch from 8ba69e3 to 7a59035 Compare April 1, 2017 07:09
@soyuka
soyuka merged commit 9a63fdc into api-platform:2.0 Apr 1, 2017
@soyuka
soyuka deleted the hotfix/filter-eager-loading-order-by-hidden branch April 1, 2017 07:24

private function toDQLString(string $dql): string
{
return preg_replace('/\\r\\n|\\n/', '', str_replace(' ', '', $dql));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we improve the regex then there'd be no need for the str_replace 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

haha yeah appveyor behavior was driving me crazy, intent was first to use PHP_EOL then I ended up with the regexp. Anyway, no big deal this is just to make tests more readable.

hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
…loading-order-by-hidden

Fix api-platform#1021 order by hidden eager loading
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.

3 participants