Created
December 12, 2016 11:00
-
-
Save MacDada/e032f6d9deaf09308e994278e66d92ff to your computer and use it in GitHub Desktop.
What is that for?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\ORM\EntityRepository; | |
class FooRepository extends EntityRepository | |
{ | |
public function save(Foo $foo) | |
{ | |
$em = $this->getEntityManager(); | |
$uof = $em->getUnitOfWork(); | |
if ($uof->isEntityScheduled($foo)) { | |
throw new \RuntimeException(sprintf( | |
'Entity %s is stored in database -> id = %d', | |
Foo::class, | |
$foo->getId() | |
)); | |
} | |
$em->persist($foo); | |
$em->flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment