Closed nWidart closed 8 years ago
@nWidart, you need to specify the selected field on your main model when using relationships to avoid this issue. I also encountered this and thus I updated the demo and added a note like below:
// It is advised that you include select('table.*') on query to avoid weird issues where id from related model replaces the id of the main model.
$posts = Post::with('user')->select('posts.*');
Hello,
Thank you, adding ->select('users.*')
did indeed fix the swapping of ID issue. (although not fixing #522)
2 app developers that i'd love chat in this issue >.<
// It is advised that you include select('table.') on query to avoid weird issues where id from related model replaces the id of the main model. $posts = Post::with('user')->select('posts.');
I think this info must be in main documentation https://yajrabox.com/docs/laravel-datatables/master/relationships
Becose i spent 4 hours to find this topic
Hello,
Summary of problem or feature request
I have a table of users, where the last column is a relation (company name). Meaning my
getColumns
array has one key as following:I also have a custom partial to add actions, in my ajax method:
This is the content of the partial, nothing fancy, just view/edit/delete buttons:
On display this works perfectly, no issues.
However, when filtering on the company name it changes the
$id
variable in the action partial to the id of a company for that row. This obviously is an issue since the view/edit/delete buttons are no more pointing to the correct ID (user id).Expected behaviour
When ordering on the
company.name
column, the$id
should still be the id of the main data (user id in this case)System details
Have I missed some option/config somewhere so that it keep using the correct
$id
on the row ?Thank you!