Skip to content

Commit 111d8aa

Browse files
committed
PHPORM-101 Allow empty insert batch for consistency with Eloquent SQL
1 parent 56a7233 commit 111d8aa

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ public function testFind(): void
225225
$this->assertEquals(35, $check->age);
226226
}
227227

228+
public function testInsertEmpty(): void
229+
{
230+
$success = User::insert([]);
231+
$this->assertTrue($success);
232+
}
233+
228234
public function testGet(): void
229235
{
230236
User::insert([

0 commit comments

Comments
 (0)