mehdi-fathi/eloquent-filter

Column in where clause is ambiguous

JordanR-Surge opened this issue · 2 comments

When an Eloquent query contains a join the where clause generated by the filters becomes ambiguous

To Reproduce
Steps to reproduce the behavior:

This type of query will break due to an ambiguous column in the sql
Users::select('users.name')->join('posts', 'posts.user_id', '=', 'users.id')->filter(['name' => 'test'])->get()

Sql Generated: SELECT users.name FROM users JOIN posts ON posts.user_id = users.id WHERE name=test;

To Fix
Add the table name to the where clauses, maybe there could be a config for this?

I found a work around for the time being, it isn't the best though. If you add the model as a relation to itself then you can use a relation filter to get the where clause to behave.

Not very ideal but it works

@JordanR-Surge This package doesn't support add an alias table in all conditions. You are right. I'll try to fix it in later versions.