I'd like to know if it is possible to create entities dynamically and persist them. For example I have
class Member {
private $adress; //OneToOne(targetEntity="Adress", inversedBy="Member", cascade={"persist", "remove"})
And a class Adress
class Adress
private $member //...
private $city // string
I want to set the values dynamically. I have every getter/setter name in a string (In this case Member.Adress.City
, and a function that works like this (simplified)
$data = explode('.', 'Adress.City');
$entity = Object; //Here, $entity is an empty Member
$cursor = $entity;
//-1 is to target only getters, and not setters
for($i = 0; $i < (count($data) - 1); $i++) {
$getter = 'get' . $data[$i];
$cursor = $cursor->$getter();
}
$setter = 'set' . $data[count($data) - 1];
$cursor->$setter($value);
$em->persist($entity);
Sadly, this doesnt work.. I can only set direct values, like Member.Name
, but not relational entities. Is there a way to work this out ? Thanks !