Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2cf1828

Browse files
committed
Ensure Hydratation of _count is done in a single query
1 parent b55bdc6 commit 2cf1828

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

‎tests/Eloquent/EloquentWithCountTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace MongoDB\Laravel\Tests\Eloquent;
44

5+
use Illuminate\Support\Facades\DB;
56
use MongoDB\Laravel\Eloquent\Model;
67
use MongoDB\Laravel\Tests\TestCase;
78

9+
use function count;
10+
811
/** Copied from {@see \Illuminate\Tests\Integration\Database\EloquentWithCountTest\EloquentWithCountTest} */
912
class EloquentWithCountTest extends TestCase
1013
{
@@ -37,6 +40,7 @@ public function testItBasic()
3740

3841
public function testWithMultipleResults()
3942
{
43+
$connection = DB::connection('mongodb');
4044
$ones = [
4145
EloquentWithCountModel1::create(['id' => 1]),
4246
EloquentWithCountModel1::create(['id' => 2]),
@@ -50,6 +54,7 @@ public function testWithMultipleResults()
5054
$ones[2]->twos()->create(['value' => 1]);
5155
$ones[2]->twos()->create(['value' => 2]);
5256

57+
$connection->enableQueryLog();
5358
$results = EloquentWithCountModel1::withCount([
5459
'twos' => function ($query) {
5560
$query->where('value', '>=', 2);
@@ -61,6 +66,9 @@ public function testWithMultipleResults()
6166
['id' => 2, 'twos_count' => 0],
6267
['id' => 3, 'twos_count' => 1],
6368
], $results->get()->toArray());
69+
70+
$connection->disableQueryLog();
71+
$this->assertEquals(2, count($connection->getQueryLog()));
6472
}
6573

6674
public function testGlobalScopes()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /