In my Symfony app, I have a function that saves a record using Doctrine:
public function save(Car $car): void
{
$this->getEntityManager()->persist($car);
$this->getEntityManager()->flush($car);
}
But in recent days, I get a lot of log entries like this:
Calling Doctrine\ORM\EntityManager::flush() with any arguments to flush specific entities is deprecated and will not be supported in Doctrine ORM 3.0.
What should I do instead?
The deprecation warning indicates that passing specific entities to EntityManager::flush()
is deprecated in Doctrine ORM and will be removed in version 3.0. Instead of flushing specific entities, you should call flush()
without arguments. This flushes all pending changes in the persistence context managed by the EntityManager :
public function save(Car $car): void
{
$entityManager = $this->getEntityManager();
$entityManager->persist($car);
$entityManager->flush(); // Flush all changes
}