-
Notifications
You must be signed in to change notification settings - Fork 475
Open
Description
When the query builder is used in combination with joins, the parent_id (and probably others) column is ambiguous:
"SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'parent_id' in where clause is ambiguous (SQL: select count(*) as aggregate from (select '1' as row from
productsleft joinshopsonshops.id=products.shop_idleft joincategoriesoncategories.id=products.category_idwhereparent_idis null) AS count_row_table)"
using the following query:
$products = \Product::whereIsRoot()
->leftJoin('shops', 'shops.id', '=', 'products.shop_id')
->leftJoin('categories', 'categories.id', '=', 'products.category_id')
->select(['products.id', 'shops.name as shop', 'products.image', 'products.brand', 'products.name',
'products.unit', 'products.similarity', 'categories.name as category'
]);For myself I quickly fixed it in QueryBuilder.php by altering the whereIsRoot() method to:
public function whereIsRoot()
{
$this->query->whereNull($this->model->getTable().'.'.$this->model->getParentIdName());
return $this;
}But I think there are multiple places in the query builder that are incompatible with joins (still have to encounter them).
bohdan-shulha and SlyDeath
Metadata
Metadata
Assignees
Labels
No labels