电子商务的 Doctrine ODM 模式

Doctrine ODM schema for E-Commerce

我是初学者,想了解有关 nosql、mongodb、文档结构的知识。我尝试为电子商务平台制作文档。因此,我有一个 product.json 和映射文档,但我对学说 odm 参考关系感到困惑。我的代码不起作用。

我想要的结构

    Product 
{
    id: 
    name:
    price: [{price1, discount2}, {price2, discount2}, ...]
    images: [{img1,timg1}, {img2,tim2}]
    comments: {[id, username, comment], ...}
    shop: [{shopinfo...}]

}

所以,我认为价格、图片和评论应该是嵌入文档。商店,产品是一对一的关系吧?我正在使用 api-platform with mongodb 中的学说 odm 参考对其进行编码。 Here 是我的代码。

我是使用 doctrine odm 引用来完成的。要创建引用,我们必须创建变量以在彼此之间进行交互 classes。例如,在 Product class

/**
 * @ODM\ReferenceMany(targetDocument=Price::class, mappedBy="product", cascade={"all"}, storeAs="id")
 */

public $prices;

价格class

/**
 * @ODM\ReferenceOne(targetDocument=Product::class, inversedBy="prices", storeAs="id")
 */

public $product;

在api-平台引用可以被iri引用使用。