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 DoctrineORMEntityManager::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?
2
Answers
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 callflush()
without arguments. This flushes all pending changes in the persistence context managed by the EntityManager :There is a potential issue with the flush() method usage in Doctrine.
It worked for me when I removed the $car parameter from flushing
}
so it looks like passing an entity to flush() is not supported in newer versions of Doctrine and will produce an error