Skip to content

Instantly share code, notes, and snippets.

@MacDada
Created December 12, 2016 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MacDada/e032f6d9deaf09308e994278e66d92ff to your computer and use it in GitHub Desktop.
Save MacDada/e032f6d9deaf09308e994278e66d92ff to your computer and use it in GitHub Desktop.
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