Skip to content

PHPORM-101 Allow empty insert batch for consistency with Eloquent SQL #2645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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