Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-128

Consider adding EntityManager#link/unlink methods for direct association manipulation

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0-ALPHA2
    • Fix Version/s: 2.x
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      A problem when working with collection-valued associations is that almost all operations except add($obj) require the collection to become initialized in order for the operation to be performed properly. While this is all correct and beautiful OO-wise it may be problematic at times with regards to performance. Hence we might want to consider to provide some convenient methods along the lines of link/unlink (name suggestions?) which allow more direct, less OO collection manipulation. Such methods obviously would bypass the normal object lifecycle and the changes done through these methods will not be reflected in the in-memory objects and collections, unless the user keeps them in-synch himself.

        Issue Links

          Activity

          Roman S. Borschel created issue -
          Roman S. Borschel made changes -
          Field Original Value New Value
          Issue Type Improvement [ 4 ] New Feature [ 2 ]
          Hide
          Benjamin Eberlei added a comment -

          Questions

          • I suppose link and unlinked entities would then handled by UnitOfwork commit also?
          • Since the collection is not initialized, one does not know upfront if the action will be successful, what happens if:
            • an entity is linked with a collection, although they are already connected.
            • an entity is unlinked from a collection it is not in.

          Regarding the naming, i like link/unlink.

          Show
          Benjamin Eberlei added a comment - Questions I suppose link and unlinked entities would then handled by UnitOfwork commit also? Since the collection is not initialized, one does not know upfront if the action will be successful, what happens if: an entity is linked with a collection, although they are already connected. an entity is unlinked from a collection it is not in. Regarding the naming, i like link/unlink.
          Hide
          Roman S. Borschel added a comment -

          What do you mean by "handled by UnitOfWork commit" ? Whether the SQL is "scheduled" or executed immediately? Interesting question.
          Scheduling would probably be better but also more difficult.

          As far as usage is concerned, I currently imagine it as follows:

          // EntityManager#link($sourceObj, $field, $targetObj)
          $user = $em->getReference($userId); // $userId probably from request parameters
          $address = $em->getReference($addressId); // $addressId probably from request parameters
          $em->link($user, 'addresses', $address);
          

          "What happens if: an entity is linked with a collection, although they are already connected."

          Probably an SQL error which results in an exception from the driver. Depends on the database constraints though.

          "What happens if: an entity is unlinked from a collection it is not in"

          Probably nothing, at least not from the SQL side. An exception could be thrown from Doctrine itself if the update affected 0 rows.

          Thanks for these initial questions. Thats definitely food for thought. Keep it coming.

          Show
          Roman S. Borschel added a comment - What do you mean by "handled by UnitOfWork commit" ? Whether the SQL is "scheduled" or executed immediately? Interesting question. Scheduling would probably be better but also more difficult. As far as usage is concerned, I currently imagine it as follows: // EntityManager#link($sourceObj, $field, $targetObj) $user = $em->getReference($userId); // $userId probably from request parameters $address = $em->getReference($addressId); // $addressId probably from request parameters $em->link($user, 'addresses', $address); "What happens if: an entity is linked with a collection, although they are already connected." Probably an SQL error which results in an exception from the driver. Depends on the database constraints though. "What happens if: an entity is unlinked from a collection it is not in" Probably nothing, at least not from the SQL side. An exception could be thrown from Doctrine itself if the update affected 0 rows. Thanks for these initial questions. Thats definitely food for thought. Keep it coming.
          Hide
          Roman S. Borschel added a comment -

          Pushed back.

          Show
          Roman S. Borschel added a comment - Pushed back.
          Roman S. Borschel made changes -
          Fix Version/s 2.x [ 10090 ]
          Fix Version/s 2.0 [ 10021 ]
          Benjamin Eberlei made changes -
          Link This issue is referenced by DDC-546 [ DDC-546 ]
          Benjamin Eberlei made changes -
          Workflow jira [ 10362 ] jira-feedback [ 13836 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback [ 13836 ] jira-feedback2 [ 15700 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 15700 ] jira-feedback3 [ 17957 ]

          This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

          • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-128, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

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

              Dates

              • Created:
                Updated: