Symfony1 信条中n:m关系的性质
水鬼 我的对象有以下模式:Symfony1 信条中n:m关系的性质,symfony1,doctrine,doctrine-1.2,Symfony1,Doctrine,Doctrine 1.2,水鬼 我的对象有以下模式: Product: columns: name: { type: string(255) } Basket: columns: current_status: { type: integer } relations: Products: { class: Product, refClass: BasketProducts, onDelete: CASCADE } BasketProducts: col
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访问quantity字段?您需要直接查询中间表才能执行此操作 这样做的一个好方法是在Basket.class.php中添加一个函数,该函数将根据BasketID检索所需的数据 如果希望在获取特定篮子时包含数据,也可以在BasketTable.class.php中创建函数(即getBasketWithProductQuantilities()) 我现在手头没有任何条令代码