class User { /** @Id */ private $id; /** @String */ private $name; /** @Collection */ private $logs = array(); }
$o = $dm->findOne(':User', array('name' => $arguments['name'])); $found = true; if (!$o) { $found = false; $o = new User(); } $o->setName($arguments['name']); $o->addLog( array('a' => 'b' )); $dm->persist($o); $dm->flush();
or a EmbeddedMany field, and try to add to add 2 objects with the same content the same thing happens:
class User { /** @Id */ private $id; /** @String */ private $name; /** @EmbedMany(targetDocument="UserLog") */ private $logs = array(); }
$o = $dm->findOne(':User', array('name' => $arguments['name'])); $found = true; if (!$o) { $found = false; $o = new User(); } $o->setName($arguments['name']); $l = new UserLog(); $l->setMsg('Testing'); $o->addLog($l); $dm->persist($o); $dm->flush();
If I change $l->setMsg('Testing'.time());
then it adds all the instances.