2

嗨伙计们

我的对象有以下架构:

Product:
  columns:
    name:          { type: string(255) }

Basket:
  columns:
    current_status: { type: integer }
  relations:
    Products:     { class: Product, refClass: BasketProducts, onDelete: CASCADE }

BasketProducts:
  columns:
    product_id:   { type: integer, primary: true }
    basket_id:    { type: integer, primary: true }
    quantity:     { type: integer(4) }
  relations:
    Product:      { local: product_id, onDelete: CASCADE }
    Basket:       { local: basket_id, onDelete: CASCADE }

现在在前端,我尝试向用户展示购物篮,通过

foreach($basket->getProducts() as $product) {
  echo $product->getId();
  echo $product->getName();
}

现在的问题是,我如何从 BasketProducts 访问数量字段?

4

1 回答 1

1

您需要直接查询中间表才能执行此操作。

一个很好的方法是在您的 Basket.class.php 中添加一个函数,该函数将根据 BasketID 检索您需要的数据。

如果您想在获取特定篮子时包含数据(即 getBasketWithProductQuantities()),也可以在 BasketTable.class.php 中创建该函数

目前我手头没有任何教义代码。

于 2011-05-09T18:54:02.130 回答