You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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)
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.
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.
The text was updated successfully, but these errors were encountered: