use DoctrineODMMongoDBMappingAnnotations as ODM;
/**
* @ODMDocument()
*/
class My_Doctrine_Model
{
/** @ODMid */
protected $id;
public function getId()
{
return $this->id;
}
public function setId($value)
{
$this->id = $value;
return $this;
}
}
法典
$myModel = new My_Doctrine_Model();
$myModel->setId(new MongoId());
// Id is my set id
$dm->persist($myModel);
// Id is my set id
$dm->flush();
// Id is overwritten and the object is inserted with an other one
为什么教条凌驾于我的 set? 我能否防止这种情况?
新 页: 1 PersistenceBuilder:prepareInsertData 当检查看是否有id时,就没有。 我不知道,为什么这个荒谬的田地脱离了变化。
Update
我读了一部略微多的法典,发现其原因是最后的<编码>if。 UnitOfWork:getDocumentActualData 。
else if ( ! $class->isIdentifier($name) || $class->isIdGeneratorNone()) {
$actualData[$name] = $value;
}
There is no else
so no value get set for the id.
Is this a deliberate design choice by the developers?
Solved
This was updated in a recent commit which I haven t updated to. I am not completely sure this is intended though.
https://github.com/doctrine/mongodb-odm/commit/fb2447c01cb8968255383ac5700f95b4327468a3#L2L503