Skip to content

Commit 8e12433

Browse files
committed
PHPORM-101 Allow empty insert batch for consistency with Eloquent SQL
1 parent 849cb1f commit 8e12433

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Query/Builder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,11 @@ public function whereBetween($column, iterable $values, $boolean = 'and', $not =
613613
/** @inheritdoc */
614614
public function insert(array $values)
615615
{
616+
// Allow empty insert batch for consistency with Eloquent SQL
617+
if ($values === []) {
618+
return true;
619+
}
620+
616621
// Since every insert gets treated like a batch insert, we will have to detect
617622
// if the user is inserting a single document or an array of documents.
618623
$batch = true;

tests/ModelTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use MongoDB\Laravel\Tests\Models\Item;
2626
use MongoDB\Laravel\Tests\Models\MemberStatus;
2727
use MongoDB\Laravel\Tests\Models\Soft;
28+
use MongoDB\Laravel\Tests\Models\SqlBook;
2829
use MongoDB\Laravel\Tests\Models\User;
2930

3031
use function abs;
@@ -217,6 +218,12 @@ public function testFind(): void
217218
$this->assertEquals(35, $check->age);
218219
}
219220

221+
public function testInsertEmpty(): void
222+
{
223+
$success = User::insert([]);
224+
$this->assertTrue($success);
225+
}
226+
220227
public function testGet(): void
221228
{
222229
User::insert([

0 commit comments

Comments
 (0)