persist() and flush() – Symfony

Call $entityManager->persist() and pass the object to save. And then $entityManager->flush(). use Doctrine\ORM\EntityManagerInterface; class QuestionController extends AbstractController { public function new(EntityManagerInterface $entityManager) { $entityManager->persist($question); $entityManager->flush(); } } Yes, you need both lines. The persist() call simply says: Hey Doctrine! Please be “aware” of this Question object. The persist line does not make any queries. The INSERT query happens when we call flush(). The flush() method says: Yo Doctrine! Please look at all of the objects that you are “aware” of and make …