-
Notifications
You must be signed in to change notification settings - Fork 22
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
Error when paginating after eagerLoading #3
Comments
@Jesuso Didn't happen to me, I re-created your example and it works on me. |
@ajcastro I have just got this issue with laravel/framework:7.28.4 and ajcastro/eager-load-pivot-relations:v0.2.2 Did some debugging with the following:
and got the following results when calling
and the correct but unpaginated results when just calling
|
After a little more investigating I found how to replicate. Here is your example from above:
I can replicate with the following
|
Anyone gotten a fix for this? :( |
Same issue |
Hey @ajcastro , First let me thank you for the great package. It saved me a lot of headaches. Second, I did encounter the same issue mentioned above. This happens whenever you try to load relationships on a relationship function directly and then paginate such as @fennik showed above (but it works if you use I don't really know why, but maybe it is related to the way the paginate method works: /**
* Get a paginator for the "select" statement.
*
* @param int|null $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
$this->query->addSelect($this->shouldSelect($columns));
return tap($this->query->paginate($perPage, $columns, $pageName, $page), function ($paginator) {
$this->hydratePivotRelation($paginator->items());
});
} The
Unfortunately, I have not enough knowledge to really understand what is going wrong... But I hope those leads might help :) Have a nice day |
Reopening this so I can take a look later |
Thanks a lot 🙏🏾 |
@ajcastro did you have a chance to take a look into this? |
When chaining a ->paginate() after eager loading the following is thrown:
Call to a member function newCollection() on null in ajcastro/eager-load-pivot-relations/src/EagerLoadPivotBuilder.php on line 78
My scenario is pretty much standard (as the README shows):
Yet, for some reason, we can run:
User::find(1)->cars()->with(['pivot.color'])->get();
but can't do the following
User::find(1)->cars()->with(['pivot.color'])->paginate()
Doing some extra research it turns out on the result to
head($pivots)
insideEagerLoadPivotBuilder::eagerLoadPivotRelations()
is an array with a null value element (array:1 [0 => null]
) instead of containing the pivot itself.The text was updated successfully, but these errors were encountered: