need Eager Loading support . #248
Answered
by
magic-thomas
magic-thomas
asked this question in
Q&A
-
First of all, I really thanks for this great package. I feel that this package is what I wanted for a long time. Anyway, I tried powergrid-demo . Downloaded / installed / run fine as it is . But I put following code to prevent lazy loading in AppServiceProvider.php use Illuminate\Database\Eloquent\Model;
public function boot()
{
Model::preventLazyLoading( true );
} After runing again, I got error. Attempted to lazy load [category] on model [App\Models\Dish] but lazy loading is disabled. I guess it is cause of datasource() function. public function datasource(): ?Builder
{
return Dish::query()
->join('categories', function ($categories) {
$categories->on('dishes.category_id', '=', 'categories.id');
})
->join('kitchens', function ($categories) {
$categories->on('dishes.kitchen_id', '=', 'kitchens.id');
})
->select('dishes.*', 'categories.name as category_name');
} How can I use Eager Loading with Join or relations ('with') ? Eager Loading is very important for my projects. Can someone help me ? |
Beta Was this translation helpful? Give feedback.
Answered by
magic-thomas
Jan 30, 2022
Replies: 1 comment
-
I found answer . actually It was my mistake. public function datasource(): ?Builder
{
return Dish::query()
->with('category')
->with('kitchen');
} it works. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
magic-thomas
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found answer .
actually It was my mistake.
it works.