Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
What is that for?
<?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