Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-22

EntityManager#refresh() should also refresh associations.

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-ALPHA3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Initially this issue was brought up by DC-41 which in turn led to DDC-21. The implementation of DDC-21 requires a working refresh() implementation that also refreshes associations.

      1) For the state of the entity that is refreshed itself this is self-explanatory (simple select on the primary table, this is what already works).

      2) For single-valued associations the proper query depends on whether the entity being refreshed represents the owning side or the inverse side of the association. If it is the inverse side, a simple query like this should do:

      select addresses.id, ... from addresses where addresses.user_id=?
      

      If it is the owning side, a join may be required:

      select addresses.id, ... from addresses inner join users on addresses.id = users.address_id where users.id=?
      

      3) For one-to-many collections, a simple select on the target entity table, similar to the following should do:

      select .... from phonenumbers ... where phonenumbers.user_id=?
      

      For many-to-many collections a similar select that joins over the join table is required.

      An clever way for collections might be to not trigger this SQL immediately on refresh() but to simply mark the collection as uninitialized again so that the first access would trigger the reload, similar to a lazy-load.

      Note that the collection itself is refreshed, not the state of the entities contained therein.
      Also note that only associations need to be refreshed that were already initialized. If an associated collection is uninitialized, it does not need to be refreshed. If an associated single-valued proxy is uninitialized, it does not need to be refreshed.

        Issue Links

          Activity

          Roman S. Borschel created issue -
          Roman S. Borschel made changes -
          Field Original Value New Value
          Link This issue is required for DDC-21 [ DDC-21 ]
          Roman S. Borschel made changes -
          Priority Major [ 3 ] Critical [ 2 ]
          Fix Version/s 2.0-BETA1 [ 10030 ]
          Component/s ORM [ 10012 ]
          Roman S. Borschel made changes -
          Description Initially this issue was brought up by DC-41 which in turn led to DDC-21. The implementation of DDC-21 requires a working refresh() implementation that also refreshes associations. Initially this issue was brought up by DC-41 which in turn led to DDC-21. The implementation of DDC-21 requires a working refresh() implementation that also refreshes associations.

          1) For the state of the entity that is refreshed itself this is self-explanatory (simple select on the primary table).

          2) For single-valued associations the proper query depends on whether the entity being refreshed represents the owning side or the inverse side of the association. If it is the inverse side, a simple query like this should do:

          {code:sql}
          select addresses.id, ... from addresses where addresses.user_id=?
          {code}

          If it is the owning side, a join may be required:

          {code:sql}
          select addresses.id, ... from addresses inner join users on addresses.id = users.address_id where users.id=?
          {code}

          3) For one-to-many collections, a simple select on the target entity table, similar to the following should do:

          {code:sql}
          select .... from phonenumbers ... where phonenumbers.user_id=?
          {code}

          For many-to-many collections a similar select that joins over the join table is required.

          An clever way for collections might be to not trigger this SQL immediately on refresh() but to simply mark the collection as uninitialized again so that the first access would trigger the reload, similar to a lazy-load.

          Note that the collection itself is refreshed, not the state of the entities contained therein.
          Also note that only associations need to be refreshed that were already initialized. If an associated collection is uninitialized, it does not need to be refreshed. If an associated single-valued proxy is uninitialized, it does not need to be refreshed.
          Roman S. Borschel made changes -
          Description Initially this issue was brought up by DC-41 which in turn led to DDC-21. The implementation of DDC-21 requires a working refresh() implementation that also refreshes associations.

          1) For the state of the entity that is refreshed itself this is self-explanatory (simple select on the primary table).

          2) For single-valued associations the proper query depends on whether the entity being refreshed represents the owning side or the inverse side of the association. If it is the inverse side, a simple query like this should do:

          {code:sql}
          select addresses.id, ... from addresses where addresses.user_id=?
          {code}

          If it is the owning side, a join may be required:

          {code:sql}
          select addresses.id, ... from addresses inner join users on addresses.id = users.address_id where users.id=?
          {code}

          3) For one-to-many collections, a simple select on the target entity table, similar to the following should do:

          {code:sql}
          select .... from phonenumbers ... where phonenumbers.user_id=?
          {code}

          For many-to-many collections a similar select that joins over the join table is required.

          An clever way for collections might be to not trigger this SQL immediately on refresh() but to simply mark the collection as uninitialized again so that the first access would trigger the reload, similar to a lazy-load.

          Note that the collection itself is refreshed, not the state of the entities contained therein.
          Also note that only associations need to be refreshed that were already initialized. If an associated collection is uninitialized, it does not need to be refreshed. If an associated single-valued proxy is uninitialized, it does not need to be refreshed.
          Initially this issue was brought up by DC-41 which in turn led to DDC-21. The implementation of DDC-21 requires a working refresh() implementation that also refreshes associations.

          1) For the state of the entity that is refreshed itself this is self-explanatory (simple select on the primary table, this is what already works).

          2) For single-valued associations the proper query depends on whether the entity being refreshed represents the owning side or the inverse side of the association. If it is the inverse side, a simple query like this should do:

          {code:sql}
          select addresses.id, ... from addresses where addresses.user_id=?
          {code}

          If it is the owning side, a join may be required:

          {code:sql}
          select addresses.id, ... from addresses inner join users on addresses.id = users.address_id where users.id=?
          {code}

          3) For one-to-many collections, a simple select on the target entity table, similar to the following should do:

          {code:sql}
          select .... from phonenumbers ... where phonenumbers.user_id=?
          {code}

          For many-to-many collections a similar select that joins over the join table is required.

          An clever way for collections might be to not trigger this SQL immediately on refresh() but to simply mark the collection as uninitialized again so that the first access would trigger the reload, similar to a lazy-load.

          Note that the collection itself is refreshed, not the state of the entities contained therein.
          Also note that only associations need to be refreshed that were already initialized. If an associated collection is uninitialized, it does not need to be refreshed. If an associated single-valued proxy is uninitialized, it does not need to be refreshed.
          Roman S. Borschel made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Roman S. Borschel made changes -
          Status In Progress [ 3 ] Closed [ 6 ]
          Fix Version/s 2.0-ALPHA3 [ 10029 ]
          Fix Version/s 2.0-BETA1 [ 10030 ]
          Resolution Fixed [ 1 ]
          Benjamin Eberlei made changes -
          Workflow jira [ 10115 ] jira-feedback [ 15417 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback [ 15417 ] jira-feedback2 [ 17281 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 17281 ] jira-feedback3 [ 19538 ]

            People

            • Assignee:
              Roman S. Borschel
              Reporter:
              Roman S. Borschel
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: