我几乎完成了一个大型应用程序; 几天前,我看到Martin Fowler关于"NOSQL"的演讲.之后我意识到我一直在使用Mongo作为关系数据库,所以我决定重构我的模式.但是,我从一个来自"RDBMS"世界的人那里听到了很多关于诚信的内容; 我真的明白它有多重要,在"NOSQL"引擎中可以实现数据完整性吗?
更明确一点,这是一个简单的例子:
比方说,我有一个product,inventory在我的系统实体,
在我的inventory参考product_id中定义产品,
目前inventory我的mongo系列看起来像这样
{'inventory' :{'product_id' : '1', 'count' : 15}}
那么我可以inventory在我的系统中存储这样的东西:
{'inventory' :{'product' : {'id' : 1, 'name' : 'book'}, 'count' : 15}}
并且仍然可以实现数据完整性吗?如果我更改产品的名称_id : 1 中product的实体,然后发生什么事-我将循环更新所有的inventory收藏?
在构建一个值对象时,我有一个简单的问题,该值对象中具有特定类型的值对象的集合,如何构造该对象?
举个例子,假设您有一个picture需要多个dimensions
选项1 :
Class Picture implements valueObject{
public function __construct(array $dimensions){
foreach($dimensions as $dimension){
// check if instance of `dimension` value object
}
}
}
Run Code Online (Sandbox Code Playgroud)
选项2:
Class Picture implements valueObject{
public function __construct(DimensionCollection $dimensions){
}
}
Class DimensionCollection implements Traversable{
public function add(Dimension $dimension){
// add to array
}
}
Run Code Online (Sandbox Code Playgroud)
选项2偏离路线似乎更合乎逻辑,但是是否有另一种模式可以更好地从DDD的接受角度出发?