Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next level relations translations like hasMany are not lazy loaded #400

Open
camohub opened this issue Apr 10, 2024 · 1 comment
Open

Next level relations translations like hasMany are not lazy loaded #400

camohub opened this issue Apr 10, 2024 · 1 comment
Labels

Comments

@camohub
Copy link

camohub commented Apr 10, 2024

I am not sure if it is a bug. Hope it is not. The problem is that if I load relations through $with the relation translations are not lazy loaded. It generates huge amount of sql requests one for each relation entity.

  • PHP 8.1
  • Laravel 9
  • aAtrotomic/Laravel-translatable: 11.12.1

We use this package with Spatie/Querybuilder package. But it should be irelevant.

I hope there is a way to set up lazy loading also on relations entities.
lazy

@camohub camohub added the bug label Apr 10, 2024
@Oleksandr-Moik
Copy link
Contributor

Hi, @camohub. Please, provide your code example for the problem.

Because, if you need to use translations from nested models, in general, case you need to load translations too, for example:

Post::with('postCategories.translation')->get();
// or
Post::with([
  'postCategories' => fn ($query) => $query->withTranslation(),
])

And you say you use Spatie/Querybuilder, explicitly include them, or modify the query how you need:

QueryBuilder::for(Post::class)
    ->with('postCategories.translation')
    ->get();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants