Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
-
The aggregate functions could also throw an exception when being called with a nested relationship. You can define a direct relationship by "skipping" the class Shelf extends Model
{
public function reviews()
{
return $this->belongsToMany(
Review::class,
'book_shelf',
'shelf_id', 'book_id', null, 'book_id'
);
}
}
Shelf::withAvg('reviews', 'rating'); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
Call to undefined method
error is thrown when using nested relationship on aggregate functions likewithAvg
. I was able to debug this and found out thatgetRelationWithoutConstraints
is directly calling the relation parameter as a function.In my use case, I'm trying to get the average of book reviews from a shelf model.
Getting the reviews directly from the book model works fine, however.
Related to #38049 and #38079
Steps To Reproduce:
C
through model A;A::withAvg('b.c', 'd')
; // This will throw an errorB::withAvg('c', 'd')
instead, it will not throw an error.Beta Was this translation helpful? Give feedback.
All reactions