Skip to content

Commit

Permalink
PHPORM-101 Allow empty insert batch for consistency with Eloquent SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Oct 18, 2023
1 parent 56a7233 commit 111d8aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@ public function whereBetween($column, iterable $values, $boolean = 'and', $not =
/** @inheritdoc */
public function insert(array $values)
{
// Allow empty insert batch for consistency with Eloquent SQL
if ($values === []) {
return true;
}

// Since every insert gets treated like a batch insert, we will have to detect
// if the user is inserting a single document or an array of documents.
$batch = true;
Expand Down
6 changes: 6 additions & 0 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ public function testFind(): void
$this->assertEquals(35, $check->age);
}

public function testInsertEmpty(): void
{
$success = User::insert([]);
$this->assertTrue($success);
}

public function testGet(): void
{
User::insert([
Expand Down

0 comments on commit 111d8aa

Please sign in to comment.