8000 Fix syntax error when join unrelated entity with discriminator entity by Deltachaos · Pull Request #6812 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix syntax error when join unrelated entity with discriminator entity #6812

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

Merged

Conversation

Deltachaos
Copy link
Contributor
@Deltachaos Deltachaos commented Nov 6, 2017

When joining a unrelated entity with a discriminator the join contains the table name and alias in brackets which is a syntax error (at least in SQL Server).

Exmaple:

SELECT
  c
FROM
  Doctrine\Tests\Models\Company\CompanyContract c
JOIN
  c.salesPerson s
LEFT JOIN
  Doctrine\Tests\Models\Company\CompanyEvent e WITH s.id = e.id

Results in:

SELECT
  c0_.id AS id_0,
  c0_.completed AS completed_1,
  c0_.fixPrice AS fixPrice_2,
  c0_.hoursWorked AS hoursWorked_3,
  c0_.pricePerHour AS pricePerHour_4,
  c0_.maxPrice AS maxPrice_5,
  c0_.discr AS discr_6
FROM
  company_contracts c0_
INNER JOIN
  company_employees c1_ ON c0_.salesPerson_id = c1_.id
LEFT JOIN
  company_persons c2_ ON c1_.id = c2_.id
LEFT JOIN
  (company_events c3_) ON (c2_.id = c3_.id)
WHERE
  c0_.discr IN ('fix', 'flexible', 'flexultra')

After the fix it results in:

SELECT
  c0_.id AS id_0,
  c0_.completed AS completed_1,
  c0_.fixPrice AS fixPrice_2,
  c0_.hoursWorked AS hoursWorked_3,
  c0_.pricePerHour AS pricePerHour_4,
  c0_.maxPrice AS maxPrice_5,
  c0_.discr AS discr_6
FROM
  company_contracts c0_
INNER JOIN
  company_employees c1_ ON c0_.salesPerson_id = c1_.id
LEFT JOIN
  company_persons c2_ ON c1_.id = c2_.id
LEFT JOIN
  company_events c3_ ON (c2_.id = c3_.id)
WHERE
  c0_.discr IN ('fix', 'flexible', 'flexultra')

I have created #6811 PR for backporting this to the 2.5 branch as well.

@lcobucci lcobucci force-pushed the bugfix/inheritance-joins-master branch from c2274d2 to 32c125d Compare December 17, 2017 00:25
Copy link
Member
@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

I've applied some small changes to reduce the complexity and it LGTM 👍

@lcobucci lcobucci self-assigned this Dec 17, 2017
@lcobucci lcobucci modified the milestones: 2.6.0, 2.5.14 Dec 17, 2017
lcobucci added a commit to lcobucci/doctrine2 that referenced this pull request Dec 17, 2017
@lcobucci lcobucci merged commit d3ff823 into doctrine:master Dec 17, 2017
@lcobucci
Copy link
Member

@Deltachaos 🚢 and backported! Thanks!

BourotBenjamin added a commit to BourotBenjamin/doctrine2 that referenced this pull request Dec 21, 2017
v2.5.14

This version backports bugfixes related to the generation of queries with joins
and configuration of the result set cache profile of a query.

Total issues resolved: **2**

Bug

- [6748: Fix missing null check on `AbstractQuery#setResultCacheProfile()`](doctrine#6748) thanks to @KonstantinKuklin
- [6812: Fix syntax error when join unrelated entity with discriminator entity](doctrine#6812) thanks to @Deltachaos
21skills added a commit to 21skills/orm that referenced this pull request Jan 27, 2021
Continuation of a problem from
doctrine#6812
The same problem appears if you add WITH condition to the joined entity with discriminator
greg0ire pushed a commit to piowin/orm that referenced this pull request Jul 23, 2021
Continuation of a problem from
doctrine#6812
The same problem appears if you add WITH condition to the joined entity with discriminator
greg0ire pushed a commit to piowin/orm that referenced this pull request Jul 23, 2021
Continuation of a problem from
doctrine#6812
The same problem appears if you add WITH condition to the joined entity with discriminator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0