[5.3] Return collections from the query builder #10552

Merged
merged 2 commits into from Feb 19, 2016

Projects

None yet

6 participants

@JosephSilber
Contributor

As discussed in #10478

@arrilot arrilot commented on an outdated diff Oct 11, 2015
tests/Database/DatabaseEloquentBuilderTest.php
@@ -176,7 +177,7 @@ public function testChunkCanBeStoppedByReturningFalse()
$builder = m::mock('Illuminate\Database\Eloquent\Builder[forPage,get]', [$this->getMockQueryBuilder()]);
$builder->shouldReceive('forPage')->once()->with(1, 2)->andReturn($builder);
$builder->shouldReceive('forPage')->never()->with(2, 2);
- $builder->shouldReceive('get')->times(1)->andReturn(['foo1', 'foo2']);
+ $builder->shouldReceive('get')->times(1)->andReturn(new COllection(['foo1', 'foo2']));
@arrilot
arrilot Oct 11, 2015 Contributor

typo

@GrahamCampbell GrahamCampbell added bug database proposal and removed bug labels Oct 14, 2015
@taylorotwell
Member

Going to hold off on this. DB::select returns an array and the query builder is just a light wrapper around PDO queries, so it's sensible for it to return arrays and we shouldn't feel obligated to make it return Collections just because the ORM does.

@taylorotwell taylorotwell reopened this Nov 10, 2015
@taylorotwell taylorotwell changed the title from [5.2] Return collections from the query builder to [5.3] Return collections from the query builder Nov 10, 2015
@taylorotwell
Member

We'll aim for making this change in 5.3, which will allow us to put a deprecation notice in the 5.2 deprecation notes that get on query builder will start returning a collection. That will give everyone a full 6 months notice at least that they need to accomodate this.

@GrahamCampbell
Member

Looking pretty nice to me. 👍 🚀

JosephSilber added some commits Oct 11, 2015
@JosephSilber JosephSilber Return collection from the query builder 7e87c21
@JosephSilber JosephSilber Update tests for query builder collections
2c61fb8
@JesseLeite
Contributor

We'll aim for making this change in 5.3, which will allow us to put a deprecation notice in the 5.2 deprecation notes that get on query builder will start returning a collection. That will give everyone a full 6 months notice at least that they need to accomodate this.

@taylorotwell Is this still a thing for 5.3?

@taylorotwell taylorotwell merged commit e87e4a5 into laravel:master Feb 19, 2016

2 checks passed

StyleCI The StyleCI analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@JosephSilber JosephSilber deleted the JosephSilber:qb-collection branch Feb 19, 2016
@acasar
Contributor
acasar commented Feb 19, 2016

@JosephSilber @taylorotwell Can we make a helper method so that we can just call ->all() instead of ->get()->all() if we want an array?

@JosephSilber
Contributor

I personally don't think we need one, but if we do it should definitely not be all.

Maybe asArray or something. But meh.

@acasar
Contributor
acasar commented Feb 19, 2016

Nah, that's too long imo. I'm either all or nothing :)

Of course in that case we'd also need to update Eloquent builder so that all wouldn't return an array.

@JosephSilber
Contributor
@acasar
Contributor
acasar commented Feb 19, 2016

Exactly. If we do this, it should be added as an alias of get() because it will otherwise propagate to the QueryBuilder and we'd have inconsistent behaviour: User::all() vs. User::where(...)->all()

@JosephSilber
Contributor

Which would be counter to everything we're trying to accomplish here. We'll once again end up with identical methods that return different types.

How often do you need an array that you want a separate method for that?

@GrahamCampbell
Member

I agree this is unneeded. It's only encourage people to not upgrade properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment