Skip to content

Commit

Permalink
Merge pull request #29646 from staudenmeir/insert-using
Browse files Browse the repository at this point in the history
[6.0] Return number of inserted rows from insertUsing()
  • Loading branch information
taylorotwell authored Aug 20, 2019
2 parents c451f22 + 390a864 commit 6f2a3b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2636,13 +2636,13 @@ public function insertGetId(array $values, $sequence = null)
*
* @param array $columns
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @return bool
* @return int
*/
public function insertUsing(array $columns, $query)
{
[$sql, $bindings] = $this->createSub($query);

return $this->connection->insert(
return $this->connection->affectingStatement(
$this->grammar->compileInsertUsing($this, $columns, $sql),
$this->cleanBindings($bindings)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ public function testInsertMethod()
public function testInsertUsingMethod()
{
$builder = $this->getBuilder();
$builder->getConnection()->shouldReceive('insert')->once()->with('insert into "table1" ("foo") select "bar" from "table2" where "foreign_id" = ?', [5])->andReturn(true);
$builder->getConnection()->shouldReceive('affectingStatement')->once()->with('insert into "table1" ("foo") select "bar" from "table2" where "foreign_id" = ?', [5])->andReturn(1);

$result = $builder->from('table1')->insertUsing(
['foo'],
Expand All @@ -1914,7 +1914,7 @@ function (Builder $query) {
}
);

$this->assertTrue($result);
$this->assertEquals(1, $result);
}

public function testInsertGetIdMethod()
Expand Down

0 comments on commit 6f2a3b3

Please sign in to comment.