ZF-Commons / ZfcUserDoctrineORM

Doctrine2 ORM storage adapter for ZfcUser.
BSD 3-Clause "New" or "Revised" License
89 stars 92 forks source link

Calling flush #6

Closed prolic closed 12 years ago

prolic commented 12 years ago

Why do you call $em->flush() everytime you persist? This is against the default usage of Doctrine, where you flush only once per request (ideally). I would instead prefer that flush will be called through an event listener during mvc-lifecycle, or manually in the controller action. the default usage with zend db could simple implement flush() in the mapper class as empty method doing nothing.

See: ZfcUserDoctrineORM\Mapper\UserDoctrine::persist(User $user) { $em = $this->getEntityManager(); $this->events()->trigger(FUNCTION . '.pre', $this, array('user' => $user, 'em' => $em)); $em->persist($user); $this->events()->trigger(FUNCTION . '.post', $this, array('user' => $user, 'em' => $em)); $em->flush(); // why do you call flush here? , }

ghost commented 12 years ago

There's really no harm in calling persist here. It's not worth the additional complexity in the hopes that people using this module will hook into the event.