I have a bit of problems with PreUpdate HasLifecycleCallbacks.
I have an entity, let say "A" with have a OneToOne relation with the entity "B". So I have:
/**
* @ORM\Entity()
* @ORM\HasLifecycleCallbacks
*/
class A
{
/**
* @ORM\OneToOne(targetEntity="B", inversedBy="attrA", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="fieldB", referencedColumnName="id")
*/
private $attrB;
public function __construct()
{
$this->attrB = new B();
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updateSomthing(){
//$gestor = fopen("/pruebitas.txt", "r");
$this->attrB->setDate($this->getDate());
}
}
And class B is:
class B
{
/**
* @ORM\OneToOne(targetEntity="A", mappedBy="attrB")
*/
private $attrA;
}
When I create a new entity A, everything works fine, the problem is when I update the entity A, the PreUpdate function is fire, (because it creates the file in the commented line), but the entity B does not persist in the database, even if the field in B should be updated.
Any idea to cascade the persist on the PreUpdate??
Thanks!!