use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
class My_Doctrine_Model
{
protected $id;
public function getId()
{
return $this->id;
}
public function setId($value)
{
$this->id = $value;
return $this;
}
}
And code
$myModel = new My_Doctrine_Model();
$myModel->setId(new MongoId());
$dm->persist($myModel);
$dm->flush();
Why is Doctrine overriding my dial id? And is there a way to prevent this?
The new identifier is set to PersistenceBuilder::prepareInsertDatawhen the check to check if the identifier is set says that it is not. I do not know why the id field is left outside the changeset.
Update
I have read a bit more code and found that the cause is the last ifin UnitOfWork::getDocumentActualData.
else if ( ! $class->isIdentifier($name) || $class->isIdGeneratorNone()) {
$actualData[$name] = $value;
}
There is no value else, so id will not be set.
Is this an intentional design choice by developers?
solvable
, . .
https://github.com/doctrine/mongodb-odm/commit/fb2447c01cb8968255383ac5700f95b4327468a3#L2L503