laravel-json-api / eloquent

Serialize Eloquent models to JSON API resources
MIT License
12 stars 15 forks source link

[Bug] Column 'id' in order clause is ambiguous #12

Closed joshmurrayeu closed 3 years ago

joshmurrayeu commented 3 years ago

I have built up a query within the Scheme::indexQuery() and I get the following exception when fetching the entities:

PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous

This bug occurs when joining with other tables in the indexQuery(). The defaultOrder method within the PagePagination will only use the primaryKey in the orderBy causing this exception.

joshmurrayeu commented 3 years ago

Please see PR: https://github.com/laravel-json-api/eloquent/pull/13

lindyhopchris commented 3 years ago

Thanks for reporting and providing the PR. The PR needs to be amended to use the qualifyColumn() method Eloquent already provides, but then should be mergable.

joshmurrayeu commented 3 years ago

No worries - I've updated the PR as requested. Thanks for a prompt response!

lindyhopchris commented 3 years ago

Great thanks, have merged into develop.