tdbui22
tdbui22

Reputation: 347

Doctrine ORM Update Row with ID

Is there a way to update a row directly with and ID? I just want the ability to update a table row field without querying for the object first. I tried this...

    $id = 1;
    $s = new Sandbox();
    $s->setId($id);
    $s->setFname('moon');
    $e = $em->merge($s);
    $em->flush($e);

and it tried to do an update to the database, however, it failed because it tried to update all the undefined fields as well whereas I just want to update the fname field.

Thanks

Upvotes: 2

Views: 1709

Answers (1)

Flip
Flip

Reputation: 4908

$id = 1;
$s = $em->getReference('Sandbox', $id);
$s->setFname('moon');
$em->persist($s);
$em->flush($s);

Upvotes: 3

Related Questions