Skip to content

Commit

Permalink
fix updated with provided qualified updated_at (#41133)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigopedra authored Feb 21, 2022
1 parent 95b732f commit 424bdd4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ protected function addUpdatedAtColumn(array $values)

$qualifiedColumn = end($segments).'.'.$column;

$values[$qualifiedColumn] = $values[$column];
$values[$qualifiedColumn] = Arr::get($values, $qualifiedColumn, $values[$column]);

unset($values[$column]);

Expand Down
32 changes: 32 additions & 0 deletions tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,20 @@ public function testUpdateWithTimestampValue()
$this->assertEquals(1, $result);
}

public function testUpdateWithQualifiedTimestampValue()
{
$query = new BaseBuilder(m::mock(ConnectionInterface::class), new Grammar, m::mock(Processor::class));
$builder = new Builder($query);
$model = new EloquentBuilderTestStub;
$this->mockConnectionForModel($model, '');
$builder->setModel($model);
$builder->getConnection()->shouldReceive('update')->once()
->with('update "table" set "table"."foo" = ?, "table"."updated_at" = ?', ['bar', null])->andReturn(1);

$result = $builder->update(['table.foo' => 'bar', 'table.updated_at' => null]);
$this->assertEquals(1, $result);
}

public function testUpdateWithoutTimestamp()
{
$query = new BaseBuilder(m::mock(ConnectionInterface::class), new Grammar, m::mock(Processor::class));
Expand Down Expand Up @@ -1715,6 +1729,24 @@ public function testUpdateWithAlias()
Carbon::setTestNow(null);
}

public function testUpdateWithAliasWithQualifiedTimestampValue()
{
Carbon::setTestNow($now = '2017-10-10 10:10:10');

$query = new BaseBuilder(m::mock(ConnectionInterface::class), new Grammar, m::mock(Processor::class));
$builder = new Builder($query);
$model = new EloquentBuilderTestStub;
$this->mockConnectionForModel($model, '');
$builder->setModel($model);
$builder->getConnection()->shouldReceive('update')->once()
->with('update "table" as "alias" set "foo" = ?, "alias"."updated_at" = ?', ['bar', null])->andReturn(1);

$result = $builder->from('table as alias')->update(['foo' => 'bar', 'alias.updated_at' => null]);
$this->assertEquals(1, $result);

Carbon::setTestNow(null);
}

public function testUpsert()
{
Carbon::setTestNow($now = '2017-10-10 10:10:10');
Expand Down

0 comments on commit 424bdd4

Please sign in to comment.