I use doctrine 2.1
I have two objects for the same record, one persisted and one not persisted. Instead of rewriting all properties, I would like to assign ID to the new one and call persist() in hope the proper row will be updated. In pseudo code a boostrap looks like this:
$old_a = new A(name: "a", value: "old")
$em->persist($old_a);
$em->flush()
now I have in the database a row with name “a” and value “old”. I would like to have value “new”. I could do
$a = new A(name: "a", value: "new") // create new object
$query = $em->createQuery("SELECT A a WHERE name = 'a'") // check if object with the same name already exists
$old_a = $query->getSingleResult();
$old_a->setValue($a->getValue()) // update value with the new one - here is the problem! If there are many properties I do not want to invoke many times setXXX($a->getXXX). I would like to do something like $old_a = $a or $a->setId($old_a->getId())
$em->persist(old_a) // update the row
The workaround is to create setId method and just rewrite id