[DDC-2131] Fetch join not working on class table inheritance Created: 07/Nov/12 Updated: 12/Nov/12 Resolved: 12/Nov/12 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | ORM |
| Affects Version/s: | 2.3 |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | alsar | Assignee: | Benjamin Eberlei |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
I have an entity Appointment, that is associated with application forms. The mapping info for the abstract application form looks like this: AbstractApplicationForm.php /** * @ORM\Entity() * @ORM\Table("applicationform") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discr", type="string") * @ORM\DiscriminatorMap({ * "slc" = "SlcApplicationForm", * "vsdb" = "VsdbApplicationForm", * "vss" = "VssApplicationForm", * "opzd" = "OpzdApplicationForm", * "vzu" = "VzuApplicationForm", * "opzdvzu" = "OpzdVzuApplicationForm" * }) */ abstract class AbstractApplicationForm ... I have an OneToMany connection from Appointment to AbstractApplicationForm. For instance if the query builder looks like this:
$qb->select('ap, af')
->from(Appointment::getClass(), 'ap')
->leftJoin('ap.applicationForms', 'af', 'WITH', 'af.id = 123456789')
->andWhere('ap.id = :appointment')
->setParameter('appointment', $appointment);
So with this dql i should get an appointment with filtered application forms. In this case it whould return an appointment with only one application form (that with the id 123456789). Here is the SQL that gets generated from the DQL: SELECT ... FROM program_execution_activity_appointment p8_, program_execution_activity_appointment p0_ LEFT JOIN applicationform a1_ ON p0_.id = a1_.appointment_id LEFT JOIN applicationform_slc a2_ ON a1_.id = a2_.id LEFT JOIN applicationform_vsdb a3_ ON a1_.id = a3_.id LEFT JOIN applicationform_vss a4_ ON a1_.id = a4_.id LEFT JOIN applicationform_opzd a5_ ON a1_.id = a5_.id LEFT JOIN applicationform_vzu a6_ ON a1_.id = a6_.id LEFT JOIN applicationform_opzdvzu a7_ ON a1_.id = a7_.id AND (a1_.id = 123456789) WHERE p0_.id = 1 The problem i see here is that the AND is added to the last join (applicationform_opzdvzu). But it should added to the first join (applicationform). Because the first join represents the parent entity (AbstractApplicationForm). The generated query should look like this: SELECT ... FROM program_execution_activity_appointment p0_ LEFT JOIN applicationform a1_ ON p0_.id = a1_.appointment_id AND (a1_.id = 123456789) LEFT JOIN applicationform_slc a2_ ON a1_.id = a2_.id LEFT JOIN applicationform_vsdb a3_ ON a1_.id = a3_.id LEFT JOIN applicationform_vss a4_ ON a1_.id = a4_.id LEFT JOIN applicationform_opzd a5_ ON a1_.id = a5_.id LEFT JOIN applicationform_vzu a6_ ON a1_.id = a6_.id LEFT JOIN applicationform_opzdvzu a7_ ON a1_.id = a7_.id WHERE p0_.id = 1 This sql works as expected. I hope i was clear enough what the problem is. |
| Comments |
| Comment by Benjamin Eberlei [ 12/Nov/12 ] |
|
This is a duplicate of |
| Comment by Benjamin Eberlei [ 12/Nov/12 ] |
|
This is not easy to fix as you can see |