[英]SQL Statement: Integrity constraint violation:
我正在嘗試檢查用戶是否有與 order_items 表鏈接的訂單,並且 order_items 表是否有產品,同時確保相同的用戶 ID 和訂單 ID。 我該怎么做呢?
我試圖這樣做:
$verify_order = Order::where('user_id', $user_id)
->join('order_items', 'orders.id', 'order_items.order_id')
->where('order.items.product_id', $product_id)->get();
但我收到一條錯誤消息:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'user_id' in where clause is ambiguous
Orders 和 orders_item 都有冗余的 user_id 作為列。
最好是從 orderrs_item 中刪除該列
或將表名添加到 user_id
$verify_order = Order::where('orders.user_id', $user_id)
->join('order_items', 'orders.id', 'order_items.order_id')
->where('order.items.product_id', $product_id)->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.