mehdi-fathi / eloquent-filter

Eloquent Filter is a package for filter data of models by the query strings. Easy to use and fully dynamic.
https://mehdi-fathi.github.io/eloquent-filter/
MIT License
430 stars 43 forks source link

Column in where clause is ambiguous #170

Closed JordanR-Surge closed 1 year ago

JordanR-Surge commented 3 years ago

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?

JordanR-Surge commented 3 years ago

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

mehdi-fathi commented 3 years ago

@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.