Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2710

Defer Hydrating an entity until its fields are accessed when using getReference even if its associated entities are accessed

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Can't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I feel it should be beneficial to not hydrate an entity even if its associations are accessed, when using getReference to create the entity instance,

      reason behind,
      sometimes we have a lot of associations and we are only interested in loading one, and do not require any property (excluding associations) from that entity,

      this could save us one sql query, unit it is needed,

      e.g.
      Class User {
      protected $id;
      protected $username;
      protected $password;

      .....
      .....

      // one to many
      protected $addresses;
      }

      $user = $em->getReference('..\User',1);
      $user->getAddresses(); // this should only execute query against addresses table, and not to User table

        Activity

        Hide
        beberlei Benjamin Eberlei added a comment -

        While this would be cool, this sadly is not possible with PHP. We cannot detect this correctly.

        Show
        beberlei Benjamin Eberlei added a comment - While this would be cool, this sadly is not possible with PHP. We cannot detect this correctly.

          People

          • Assignee:
            beberlei Benjamin Eberlei
            Reporter:
            anandagra Ananda Agrawal
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: