How to determine if a Doctrine entity is persisted?

EDIT: As said by @Andrew Atkinson, it seems

EntityManager->contains($entity)

is the preferred way now.

Previous answer: You have to use UnitOfWork api like this:

$isPersisted = \Doctrine\ORM\UnitOfWork::STATE_MANAGED === $entityManager->getUnitOfWork()->getEntityState($entity);

Leave a Comment