The column 'id' was specified multiple times for 'temp_table' #2531
Unanswered
wildfiregt
asked this question in
Q&A
Replies: 1 comment
-
You need to specify a select when eager loading a relationship. $comments = Comment::query()->select('comments.*')->with('users'); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary of problem or feature request
There seems to be an issue when tables have same primary column names. First page loads but not the other pages.
Code snippet of problem
Let's say we have 2 tables with this architecture :
users (id, name) comments (id, text, user_id)
I try to eager load comments with users using eloquent :
$comments = Comment::query()->with('users');
Logging the output gives the expected result
[ { "id": 1, "text": "Comment", "id_user": 1, "user" : { "id" : 2, "name" : "user 2" } } ]
So before using Yajra\Datatables, everything seems fine.
Then i call Yajra datatable like this :
return Datatables::of($comments)->make(true);
First issue : when printing json returned by Yajra, the id of Comment is messed up and takes "user" id.
First page loads, when changing the page, i get the following error
The column 'id' was specified multiple times for 'temp_table'
So there's an issue when tables have the same column name. When I changed one of those "id" to another name, the problem is gone. But that's not an ideal solution. Can't change column names of every database.
It is possible to change the request to raw sql, but that's not ideal either. Would be nice to solve this using default Eloquent models
System details
Beta Was this translation helpful? Give feedback.
All reactions