Doctrine2似乎为它的 Proxy 对象添加了延迟加载的魔力。这使我的结果不正确,我无法弄清楚是什么原因造成的。
这是我的班级模型:
类“RedProduct”继承自抽象类“Product”,它实现了接口“BaseProduct”
抽象类 Product 持有主键:
abstract class Product implements BaseProduct {
/** @Id @Column (type="integer", name="ID") @GeneratedValue */
protected $id;
public function getId() {
return $this->id;
}
}
我希望 RedProduct 在返回之前在 id 前面加上字母“R”。
class RedProduct extends Product {
public function getId() {
return 'R' . $this->id;
}
}
但在代理类中,getId() 方法(并且只有 getId() 方法)已修改为:
public function getId()
{
if ($this->__isInitialized__ === false) {
return $this->_identifier["id"];
}
$this->__load();
return parent::getId();
}