Skip to content

Updating with updated_at column triggers some weird behaviour #1726

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

Closed
wants to merge 4 commits into from
Closed
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
17 changes: 17 additions & 0 deletions src/Jenssegers/Mongodb/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,23 @@ protected function compileWhereRaw(array $where)
return $where['sql'];
}

/**
* @inheritdoc
*/
protected function addUpdatedAtColumn(array $values)
{
if (! $this->model->usesTimestamps()) {
return $values;
}

$column = $this->qualifyColumn($this->model->getUpdatedAtColumn());

return array_merge(
[$column => $this->model->freshTimestampString()],
$values
);
}

/**
* Set custom options for the query.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class AuthTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
User::truncate();
DB::collection('password_reminders')->truncate();
Expand Down
2 changes: 1 addition & 1 deletion tests/EmbeddedRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class EmbeddedRelationsTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
Mockery::close();

Expand Down
4 changes: 2 additions & 2 deletions tests/GeospatialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class GeospatialTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -43,7 +43,7 @@ public function setUp()
]);
}

public function tearDown()
public function tearDown(): void
{
Schema::drop('locations');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/HybridRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class HybridRelationsTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -11,7 +11,7 @@ public function setUp()
MysqlRole::executeSchema();
}

public function tearDown()
public function tearDown(): void
{
MysqlUser::truncate();
MysqlBook::truncate();
Expand Down
11 changes: 10 additions & 1 deletion tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ModelTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
User::truncate();
Soft::truncate();
Expand Down Expand Up @@ -548,4 +548,13 @@ public function testChunkById()

$this->assertEquals(3, $count);
}

public function testUpdateWithUpdatedAt()
{
$item = Item::create(['name' => 'sword']);
$item->update($item->toArray());

$this->assertNull($item->items);
$this->assertNull(optional($item->items)->updated_at);
}
}
2 changes: 1 addition & 1 deletion tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class QueryBuilderTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
DB::collection('users')->truncate();
DB::collection('items')->truncate();
Expand Down
4 changes: 2 additions & 2 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class QueryTest extends TestCase
{
protected static $started = false;

public function setUp()
public function setUp(): void
{
parent::setUp();
User::create(['name' => 'John Doe', 'age' => 35, 'title' => 'admin']);
Expand All @@ -18,7 +18,7 @@ public function setUp()
User::create(['name' => 'Error', 'age' => null, 'title' => null]);
}

public function tearDown()
public function tearDown(): void
{
User::truncate();
parent::tearDown();
Expand Down
2 changes: 1 addition & 1 deletion tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class QueueTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/RelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RelationsTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
Mockery::close();

Expand Down
2 changes: 1 addition & 1 deletion tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class SchemaTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
Schema::drop('newcollection');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SeederTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class SeederTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
User::truncate();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ValidationTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
User::truncate();
}
Expand Down