Skip to content

fix eager, left join if previous was a left join#789

Merged
dunglas merged 1 commit into
api-platform:masterfrom
soyuka:fix-inner-join
Oct 8, 2016
Merged

fix eager, left join if previous was a left join#789
dunglas merged 1 commit into
api-platform:masterfrom
soyuka:fix-inner-join

Conversation

@soyuka

@soyuka soyuka commented Oct 7, 2016

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

When doing a LEFT join, the next association that should be fetched in EAGER mode was doing an INNER join. As a result, there were things missing from the end results.

}

$joinColumns = $mapping['joinColumns'] ?? $mapping['joinTable']['joinColumns'] ?? null;
if ($wasLeftJoin === false) {

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.

Please use Yoda style.

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.

thanks, done

@dunglas
dunglas merged commit 2d62597 into api-platform:master Oct 8, 2016
@dunglas

dunglas commented Oct 8, 2016

Copy link
Copy Markdown
Member

Thanks @soyuka

@soyuka
soyuka deleted the fix-inner-join branch November 3, 2016 13:43
magarzon pushed a commit to magarzon/core that referenced this pull request Feb 12, 2017
fix eager, left join if previous was a left join
@wadjeroudi

wadjeroudi commented Apr 21, 2017

Copy link
Copy Markdown

@soyuka
I may have the same problem on a filter, the generated query has an inner after a left join :

SELECT DISTINCT a0_.id AS id_0, a0_.id AS id_1, a0_.id AS id_2 FROM app_manufactured_item a0_ LEFT JOIN sylius_order_item_unit s1_ ON a0_.order_item_unit_id = s1_.id LEFT JOIN sylius_order_item s2_ ON s1_.order_item_id = s2_.id INNER JOIN app_attachment_item a3_ ON a0_.attachment_item_id = a3_.id

What is the rule to decide if it should join with inner or left ?

I'm using an Existfilter and it adds the join by using the function addJoinsForNestedProperty from Abstractfilter. The addJoinOnce function seems to decide to add only inner joins.

@soyuka

soyuka commented Apr 22, 2017

Copy link
Copy Markdown
Member Author

@wadjeroudi it should only join once (code ref). What version are you using? May you open a new issue to track this? Thanks!

@wadjeroudi

Copy link
Copy Markdown

@soyuka Thx for your answer. The problem is not about the join added one time, but it's about the type of the join: inner vs left join. addJoinOnce seems to only add inner join. But you can see on my generated request that my first join was a left join. Is there any logic implemented ?
How can I force a left join ?

@soyuka

soyuka commented May 18, 2017

Copy link
Copy Markdown
Member Author

@wadjeroudi indeed we don't specify what type the join should be there. I'll work on a patch to fix this.

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

Successfully merging this pull request may close these issues.

4 participants