我有一个名为InvoiceItemMarchandise的实体,其属性为“quantity”,属性为“previousQuantity”:
class InvoiceItemMarchandise extends InvoiceItem
{
/**
* @var integer
*
* @ORM\Column(name="quantity", type="integer", nullable=true)
* @Type("integer")
*/
protected $quantity;
/**
* @var
*/
protected $previousQuantity;
}
$ quantity由ORM管理并存储到DB中。当我的实体从DB加载时,我想将$ quantity值推入$ previousQuantity,因为稍后我会在处理股票时需要这个值。但我不希望它被保存在数据库中。我试图在__construct中执行此操作,但我认为__construct仅在创建新对象时调用,而不是在从DB加载时调用。
我该怎么做?
答案 0 :(得分:0)
嗯,我正在考虑是否有超出预期范围的后果,所以在采用这个解决方案时,请理解我还未决定这是否是一个好的架构决策。< / p>
但是,它可能就像
一样简单public function setQuantity($quantity)
{
$this->previousQuantity = $this->quantity;
$this->quantity = $quantity
}
当从数据库加载实体类时,它们会与属性设置器一起使用,因此应该工作。当InvoiceItemMarchandise::$previousQuantity
为空时,您可能想要一个特殊情况。