I have three Doctrine objects: Device, which has a OneToOne relationship with Device \ Status, which in turn has a OneToOne relationship with Device \ Status \ Battery.
I have {cascade = "persist"} installed between related objects and from what I read, this should be all that is required for Doctrine to automatically save each of the entities without having to do anything on its own in the code.
Here I have problems with:
$device = new \Entities\Device(); $device->setId(100); $status = $device->getStatus(); $status->setIpAddress('192.168.0.1'); $battery = $status->getBattery(); $battery->setInternalLevel(60); $em->persist($device); $em->flush();
After executing this code, I get the following error:
Entity of type Device\Status\Battery has identity through a foreign entity Device\Status, however this entity has no identity itself. You have to call EntityManager
My question is: what is the correct way to configure my objects so that they are stored in the correct order?
The code for the objects can be found here: https://gist.github.com/1753524
All tests were performed using the Doctrine 2.2 sandbox.
source share