lazeevv
lazeevv

Reputation: 55

How dont flush the persisted entity in Symfony2 with Doctrine?

I have this action:

/**
 * @Route("/{id}", name="showpage", requirements={"id" : "\d+"})
 */
public function showAction(Car $car, Request $request)
{
    // I have fetched $car
    $form = $this->createForm(CarType::class, $car);
    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {
        $driver = new Driver();
        // Some logic...
        $em = $this->getDoctrine()->getManager();
        $em->persist($driver);
        $em->flush();
        //...
    }
    //..
 }

I want only get info and form by $car, but dont want update it. How can I block flush() for my $car?

Upvotes: 3

Views: 1460

Answers (2)

chalasr
chalasr

Reputation: 13167

Or flush only $driver.

$em->flush($driver);

Upvotes: 3

Federkun
Federkun

Reputation: 36989

You need to detach the entity. You can do that with

$em->detach($car);

Upvotes: 1

Related Questions