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.2] Fix each when there's no order by #11623

Merged
merged 2 commits into from Dec 31, 2015
Merged

[5.2] Fix each when there's no order by #11623

merged 2 commits into from Dec 31, 2015

Conversation

GrahamCampbell
Copy link
Member

Unless we add an orderby, the rows returned by chunk are undefined, the 2nd chunk could be the same as the first chunk for instance.

@@ -295,6 +295,10 @@ public function chunk($count, callable $callback)
*/
public function each(callable $callback, $count = 1000)
{
if (is_null($this->getOrderBys())) {
$this->orderBy('id', 'asc');
Copy link
Member

Choose a reason for hiding this comment

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

id may not always be available.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeh, I know. Not sure what else we can do here.

@GrahamCampbell
Copy link
Member Author

Ok, I've made another change.

*/
public function each(callable $callback, $count = 1000)
{
if (is_null($this->getOrderBys())) {
throw new RuntimeException('You must provided an ordering on the query.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be "provide"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeh, oops. Thanks. ;)

@taylorotwell taylorotwell merged commit 70d4e2d into laravel:5.2 Dec 31, 2015
@GrahamCampbell GrahamCampbell deleted the each branch December 31, 2015 17:41
@vlakoff
Copy link
Contributor

vlakoff commented Oct 30, 2016

chunk() and chunkById() methods don't have these changes, though they are basically running the same queries. This is inconsistent.

@GrahamCampbell maybe they should be modified as well for 5.4?

@GrahamCampbell
Copy link
Member Author

Perhaps. Feel free to send a PR for Taylor to review. Thanks. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants