简言之
:餐厅有一个价目表,他们可以通过在其中插入新价格的流程来更新该价目表。
因此,将生成价格订单。
检索产品的所有类别
(没问题)然后我想做一个
从产品到PriceOrderProduct的关系
我现在有:
ProductCategory::with('products.orderProduct')->orderBy('order')->get()
这让我意识到这个错误:
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias:
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'price_order_products' (SQL: select `price_order_products`.*, `price_order_products`.`product_id` as `pivot_product_id`, `price_order_products`.`id` as `pivot_id` from `price_order_products` inner join `price_order_products` on `price_order_products`.`id` = `price_order_products`.`id` where `price_order_products`.`product_id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
这些是我的表格和关系:
(我使用
price_
“我的表”的前缀)
表:价格\产品\类别
-身份证
类别信息等。
型号:ProductCategory
public function products()
{
return $this->hasMany(Product::class, 'product_category_id');
}
产品价格
-产品类别标识
型号:产品
public function categories()
{
return $this->belongsTo(ProductCategory::class, 'product_category_id');
}
public function orderProduct()
{
return $this->belongsToMany(PriceOrderProduct::class, 'price_order_products', 'product_id', 'id');
}
==========================
表:订单价格
-身份证
-餐厅id
等
public function products()
{
return $this->hasMany(PriceOrderProduct::class, 'order_id');
}
表价格\订单\产品
-订单号
-产品标识
-价格
-产品信息
型号:PriceOrderProduct
public function orders()
{
return $this->belongsTo(PriceOrder::class);
}
public function products()
{
return $this->hasMany(Product::class, 'id', 'product_id');
}