Doctrine orm Doctrine2对代理生成的影响
我想知道是否可以使用第2.4条原则进行以下操作 假设我们有一个如下所示的实体: /** * @ORM\Entity * @ORM\Table */ class SomeEntity { /** * @ORM\Id * @ORM\Column(type="bigint") * @ORM\GeneratedValue */ protected $some_really_long_named_id; public function getSomeReallyLongNamedId() { return $this->some_really_long_named_id; } } /** * {@inheritDoc} */ public function getId() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); } /** * {@inheritDoc} */ public function getSomeReallyLongNamedId() { if ($this->__isInitialized__ === false) { return parent::getSomeReallyLongNamedId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSomeReallyLongNamedId', array()); return parent::getSomeReallyLongNamedId(); }Doctrine orm Doctrine2对代理生成的影响,doctrine-orm,Doctrine Orm,我想知道是否可以使用第2.4条原则进行以下操作 假设我们有一个如下所示的实体: /** * @ORM\Entity * @ORM\Table */ class SomeEntity { /** * @ORM\Id * @ORM\Column(type="bigint") * @ORM\GeneratedValue */ protected $some_really_long_named_id; public function
有没有办法影响
ProxyGenerator
以确保调用getId()
方法时,它并不意味着延迟加载?我知道你的问题我已经很老了,但我正在寻找同一问题的解决方案
我找到了一种方法来禁用带有注释的直接延迟加载:
/** @Id **/
protected $id;
/** @IdGetter **/
public function getId() {
...
}
这将强制在代理类中进行初始化测试:
/**
* {@inheritDoc}
*/
public function getId()
{
if ($this->__isInitialized__ === false) {
return parent::getId();
}
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
return parent::getId();
}
编辑#1
getId()方法必须少于4行(@see in ProxyGenerator.php方法isShortIdentifierGetter())才能被检测为标识获取程序。我在
IdGetter
注释中找不到任何引用。这就是它所说的实施。然而,在目前的情况下,没有提到它。我不能让它工作。可能是因为我的情况不同:除了默认的getId
方法之外,我还使用了第二个getter。
/**
* {@inheritDoc}
*/
public function getId()
{
if ($this->__isInitialized__ === false) {
return parent::getId();
}
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
return parent::getId();
}