mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-1175: Call chaining for entity manager #1477
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (May 27, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user dukeofgaming:
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.
@doctrinebot commented on GitHub (May 27, 2011):
Comment created by @beberlei:
A fluent interface shouldnt be introduced just for convenience, it makes no sense here semenatically.
@doctrinebot commented on GitHub (May 30, 2011):
Comment created by dukeofgaming:
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.
@doctrinebot commented on GitHub (May 30, 2011):
Comment created by @beberlei:
No reason to reopen. We made this decision and its final
@doctrinebot commented on GitHub (May 30, 2011):
Issue was closed with resolution "Fixed"