脚本宝典收集整理的这篇文章主要介绍了php – 声明Doctrine Embeddable是否可为空,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
Doctrine 2.5提出了the Embeddable type,它显然是以价值对象为基础构建的,实际上,我认为它是我案例的完美解决方案.
但是,有一件事我不能做:声明Person :: Address可以为空,而Company :: Address不是. Embeddable的字段本身存在布尔可空属性,但当然这适用于嵌入地址的每个实体.
有人知道我是否遗漏了某些东西,或者这是否是由于技术限制,是否有解决方法等?现在,我看到的唯一解决方案是将所有Embeddable字段声明为nullable:true并在我的代码中处理约束.
Doctrine 2不支持Nullable embeddables.预计它们将用于版本3.
解决方案是“不在那里使用嵌入式,并[[]]用嵌入式替换字段[手动]”(@Ocramius)
例:
class PRoduct { private $sale_price_amount; private $sale_price_currency; public function getSalePrice(): SalePrice { if (is_null($this->sale_price_currency) || is_null($this->sale_price_amount) ) { return null; } return new SalePrice( $this->sale_price_currency,$this->sale_price_amount ); } }
(Harrison Brown小节)
以上是脚本宝典为你收集整理的php – 声明Doctrine Embeddable是否可为空全部内容,希望文章能够帮你解决php – 声明Doctrine Embeddable是否可为空所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。