Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.x
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      It would be nice to have the entity manager return $this in methods like persist and remove, so instead of having this:

      $em = $this->get('doctrine')->getEntityManager();
      $user = $em->find('AcmeHelloBundle:User', $id);
      $em->remove($user);
      $em->flush();

      One could do this:

      $em = $this->get('doctrine')->getEntityManager();
      $user = $em->find('AcmeHelloBundle:User', $id);
      $em
      ->remove($user)
      ->flush();

      It is a small improvement (and perhaps its not the best case to demonstrate it) but it makes using the entity manager more comfortable.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        A fluent interface shouldnt be introduced just for convenience, it makes no sense here semenatically.

        Show
        Benjamin Eberlei added a comment - A fluent interface shouldnt be introduced just for convenience, it makes no sense here semenatically.
        Hide
        David Vega added a comment -

        Well, I never spoke of any fluent interface, and method chaining —which can be easily confused with fluent interfaces or vice versa (read the Update at the bottom of http://martinfowler.com/bliki/FluentInterface.html)— is often used for convenience, meaning readability and practicality.

        So compare:

        $entity_manager
        ->persist($an_entity)
        ->persist($another_entity)
        ->persist($some_entity)
        ->persist($the_entity)
        ->remove($little_entity)
        ->remove($big_entity)
        ->flush();

        With:

        $entity_manager->persist($an_entity)
        $entity_manager->persist($another_entity)
        $entity_manager->persist($some_entity)
        $entity_manager->persist($the_entity)
        $entity_manager->remove($little_entity)
        $entity_manager->remove($big_entity)
        $entity_manager->flush();

        It is way less tedious and way more readable, and again, not a fluent interface, just method chaining to improve readability and ease of use.

        Show
        David Vega added a comment - Well, I never spoke of any fluent interface, and method chaining —which can be easily confused with fluent interfaces or vice versa (read the Update at the bottom of http://martinfowler.com/bliki/FluentInterface.html )— is often used for convenience, meaning readability and practicality. So compare: $entity_manager ->persist($an_entity) ->persist($another_entity) ->persist($some_entity) ->persist($the_entity) ->remove($little_entity) ->remove($big_entity) ->flush(); With: $entity_manager->persist($an_entity) $entity_manager->persist($another_entity) $entity_manager->persist($some_entity) $entity_manager->persist($the_entity) $entity_manager->remove($little_entity) $entity_manager->remove($big_entity) $entity_manager->flush(); It is way less tedious and way more readable, and again, not a fluent interface, just method chaining to improve readability and ease of use.
        Hide
        Benjamin Eberlei added a comment -

        No reason to reopen. We made this decision and its final

        Show
        Benjamin Eberlei added a comment - No reason to reopen. We made this decision and its final

          People

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

            Dates

            • Created:
              Updated:
              Resolved: