Search code examples
phpsymfonydoctrine-orm

Doctrine: How should I update my entity-saving function?


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?


Solution

  • There is a potential issue with the flush() method usage in Doctrine. It worked for me when I removed the $car parameter from flushing

    public function save(Car $car): void
    {
       $this->getEntityManager()->persist($car);
       $this->getEntityManager()->flush();
    

    }

    so it looks like passing an entity to flush() is not supported in newer versions of Doctrine and will produce an error