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

[5.7] Fix each() on BelongsToMany relationships #25832

Merged
merged 1 commit into from
Sep 30, 2018
Merged

[5.7] Fix each() on BelongsToMany relationships #25832

merged 1 commit into from
Sep 30, 2018

Conversation

staudenmeir
Copy link
Contributor

@staudenmeir staudenmeir commented Sep 30, 2018

each() doesn't work properly on BelongsToMany relationships. The relationship has its own chunk() method (that takes care of the pivot columns and the pivot relation), but it doesn't get called. Since each() is defined in the query builder, it only calls the query builder's chunk() method.

We just have to copy the query builder's each() method to the relationship.
#24096 fixed the same issue for HasManyThrough relationships.

We could also put each() in the Relation class and cover both BelongsToMany and HasManyThrough relationships with a single method.

Copy link

@alberthuang24 alberthuang24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
   * Execute a callback over each item while chunking.
   *
   * @param  \ Closure  $callback
   * @param  int  $count
   * @return bool
   */
  public function each(\Closure $callback, $count = 1000)

@taylorotwell taylorotwell merged commit 19e7b7b into laravel:5.7 Sep 30, 2018
@staudenmeir staudenmeir deleted the belongstomany-each branch September 30, 2018 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants