laravel-eloquent-join icon indicating copy to clipboard operation
laravel-eloquent-join copied to clipboard

Column in where clause is ambiguous

Open iveoles opened this issue 1 year ago • 0 comments

Hi

Just installed the package and trying to use on a query. In particular I'm trying to avoid the 3rd problem you mention in the docs with "ambiguous column".

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous (SQL: 
select projects.*, MAX(`customers`.`customername`) as sort 
from `projects` 
left join `customers` on `customers`.`customerid` = `projects`.`customer_id` and `customers`.`deleted_at` is null 
where `status` = Open and `projects`.`deleted_at` is null 
group by `projects`.`id` 
order by sort asc

Projects and Customer both have the status column on them.

Models\Project::whereStatus('Open')
->orderByJoin('customer.customername')
->get();

Am I missing something in the setup?

iveoles avatar Aug 23 '24 14:08 iveoles