Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1081

Unnecessary JOIN when selecting ManyToMany/Join Table by ID.

    Details

    • Type: Improvement Improvement
    • Status: Reopened
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      With the schema:

       
      Image
          @Id
          $id
      
      Tag
          @Id
          $Id
      
      Tag_Image
          @Id
          @OneToOne(targetEntity="Tag")
          @JoinColumn(name="tag")
          $tag
      
          @Id
          @OneToOne(targetEntity="Image")
          @JoinColumn(name="image")
          $image
      

      Given the following DQL,

          SELECT img
          FROM Image 
          LEFT JOIN img.tags tag
          WHERE tag.id=:tag
      

      Doctrine Generates this SQL

       
          SELECT i0_.id AS id1 
          FROM Image i0_ 
          LEFT JOIN Tag_Image t2_ 
              ON i0_.id = t2_.image 
          LEFT JOIN Tag t1_ 
              ON t1_.id = t2_.tag 
          WHERE t1_.id = 37
      

      Which unncessarily joins against Tag, given that the foreign key Tag.id is also found in Tag_Image.tag.

        Activity

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            David Reisch
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: