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

Eager Loading not Working for BelongsToMany Pivot Relation #6594

Closed
nouman-ashraf-awan opened this issue Nov 26, 2024 · 4 comments
Closed

Eager Loading not Working for BelongsToMany Pivot Relation #6594

nouman-ashraf-awan opened this issue Nov 26, 2024 · 4 comments
Labels
needs more info More information is required stale

Comments

@nouman-ashraf-awan
Copy link

  • Laravel Version: 9.0
  • Nova Version: 3.0
  • PHP Version: 8.1

Description:

BelongsToMany relationships with custom pivot fields are not eager loading nested relation in the Nova resource.

Detailed steps to reproduce the issue on a fresh Nova installation:

Create a Group model with a currencies relation:

public function currencies(): BelongsToMany
{
return $this->belongsToMany(
Currency::class,
CurrencyGroup::class,
'group_id',
'currency_id'
)
->withPivot('id', 'amount', 'remaining', 'type', 'begins_at', 'expires_at', 'contract_id')
->withTimestamps();
}
In Nova Resource
BelongsToMany::make('Currencies Breakdown', 'currencies', Currency::class)
->fields(new CurrencyGroupFields)
->allowDuplicateRelations()
->canSee(fn () => Setting::get('ff_enable_currency_system')),

In CurrencyGroup Model
public function currencyUsers()
{
return $this->hasMany(CurrencyUser::class, 'currency_group_id', 'id');
}

Now wants to eager load currencies.pivot.currencyUsers or some other relations in Group Resource but not working. Creating N+1 Problem.
While using detailQuery method, eager loading working for nova-api/groups/ID
but not in
/nova-api/currencies?orderBy=&page=1&perPage=5&relationshipType=belongsToMany&search=&trashed=&viaRelationship=currencies&viaResource=groups&viaResourceId=ID

Tried this package https://github.com/ajcastro/eager-load-pivot-relations too but not working in Nova.

@crynobone
Copy link
Member

Hi there,

We are no longer providing support for Laravel Nova 3.

@crynobone crynobone closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2024
@nouman-ashraf-awan
Copy link
Author

@crynobone Its not working in Nova 4 too. Can you help to resolve this.

@crynobone
Copy link
Member

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@crynobone crynobone reopened this Nov 26, 2024
@crynobone crynobone added needs more info More information is required stale labels Nov 26, 2024
@crynobone
Copy link
Member

Hey there,

We're closing this issue because it's inactive, already solved, old, or not relevant anymore. Feel free to open up a new issue if you're still experiencing this problem.

@crynobone crynobone closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is required stale
Projects
None yet
Development

No branches or pull requests

2 participants