Multiple relationships not working
scritrolf opened this issue · comments
Summary of problem or feature request
Hi, I have a model that has a number of relationships and I want to have the data of more than one these relationships available. So I use with() to eager load the relationships, but this seems to be working just for one relationship, no method chaining is possible
Code snippet of problem
public function query(Item $model): QueryBuilder
{
return $model->newQuery()->with('category')->with('description_de');
}
public function getColumns(): array
{
return [
/* Column::computed('action')
->exportable(false)
->printable(false)
->width(60)
->addClass('text-center'),
*/
// Column::make('id'),
'Warengruppe' => new \Yajra\DataTables\Html\Column([
'title' => 'Warengruppe',
'data' => 'category.description',
]),
'Beschreibung' => new \Yajra\DataTables\Html\Column([
'title' => 'Beschreibung',
'data' => 'description_de.description',
]),
];
}
is what I'm trying to achieve but no matter what order I try them, it always only loads the "category" relationship. If I work with only one "with(...)", the specific relationship works.
-
Operating System
curren sail setup
Linux 4b31dc42b2ce 6.5.0-18-generic #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux -
PHP Version
php 8.3 -
Laravel Version
"name": "laravel/framework",
"version": "v10.44.0", -
Laravel-Datatables Version
"name": "yajra/laravel-datatables",
"version": "v10.1.0",
I dug around a bit and found a solution in another issue here:
return $model->newQuery()->with('descriptionde')->with('category')->select('items.*');//->with('category');
I'm not really sure why this is needed but it's solved now :)