Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1149

Optimize OneToMany and ManyToMany without join

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Git Master
    • Fix Version/s: 2.5
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

       
      /**
       * @Entity
       * @Table(name="users")
       */
      class User {
      
          /**
           * @Column
           * @Id
           */
          public $user_id;
      
          /**
           * @Column
           */
          public $email;
      
          /**
           * @OneToMany(targetEntity="Language", mappedBy="user",fetch="EAGER")
           */
          public $languages;
      
      }
      
      /**
       * @Entity
       * @Table(name="user_languages")
       */
      class Language {
      
          /**
           * @Column
           * @Id
           */
          public $user_language_id;
      
          /**
           * @ManyToOne(targetEntity="User", inversedBy="languages")
           * @JoinColumn(name="user_id", referencedColumnName="user_id")
           */
          public $user;
      
          /**
           * @Column
           */
          public $user_id;
      }
      
      $users = $em->getRepository('User')->findAll();
      

      Result:

      SELECT t0.user_id AS user_id1, t0.email AS email2 FROM users t0
      SELECT t0.user_language_id AS user_language_id1, t0.user_id AS user_id2, t0.user_id AS user_id3 FROM user_languages t0 WHERE t0.user_id = ?
      array(1) {
        [0]=>
        string(1) "1"
      }
      array(1) {
        [0]=>
        NULL
      }
      SELECT t0.user_language_id AS user_language_id1, t0.user_id AS user_id2, t0.user_id AS user_id3 FROM user_languages t0 WHERE t0.user_id = ?
      array(1) {
        [0]=>
        string(1) "2"
      }
      array(1) {
        [0]=>
        NULL
      }
      SELECT t0.user_language_id AS user_language_id1, t0.user_id AS user_id2, t0.user_id AS user_id3 FROM user_languages t0 WHERE t0.user_id = ?
      array(1) {
        [0]=>
        string(1) "3"
      }
      array(1) {
        [0]=>
        NULL
      }
      
      ...
      

      Need result:

      SELECT t0.user_id AS user_id1, t0.email AS email2 FROM users t0
      SELECT u0_.user_language_id AS user_language_id0, u0_.user_id AS user_id1, u0_.user_id AS user_id2 FROM user_languages u0_ WHERE u0_.user_id IN (1, 2, 3)
      

        Activity

        Andrey Kolyshkin created issue -
        Andrey Kolyshkin made changes -
        Field Original Value New Value
        Attachment testDoctrine.php [ 10991 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 12634 ] jira-feedback [ 13925 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 13925 ] jira-feedback2 [ 15789 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 15789 ] jira-feedback3 [ 18046 ]
        Vladimir made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        made changes -
        Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
        Giuliano Riccio made changes -
        Status In Progress [ 3 ] Awaiting Feedback [ 10000 ]
        Guilherme Blanco made changes -
        Assignee Benjamin Eberlei [ beberlei ] Guilherme Blanco [ guilhermeblanco ]
        Guilherme Blanco made changes -
        Status Awaiting Feedback [ 10000 ] Open [ 1 ]
        Guilherme Blanco made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.5 [ 10522 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Andrey Kolyshkin
          • Votes:
            15 Vote for this issue
            Watchers:
            18 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: