From c016f2d2faacbfe9127ae2f31dda9115becb1758 Mon Sep 17 00:00:00 2001 From: Alexandru GEORGESCU Date: Fri, 8 Mar 2019 12:00:06 +0200 Subject: [PATCH 1/4] Reverting to the old addUpdatedAtColumn --- src/Jenssegers/Mongodb/Query/Builder.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index a340976e3..80bc0c8fc 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -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. * From af77c1219be0086e00a43e480442fd249ab7c0d7 Mon Sep 17 00:00:00 2001 From: Alexandru GEORGESCU Date: Fri, 8 Mar 2019 12:00:18 +0200 Subject: [PATCH 2/4] Added testing. --- tests/ModelTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 4387d1231..b9cada8ac 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -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); + } } From 24e6cea51b771357f44a9359a01f04ae7e226409 Mon Sep 17 00:00:00 2001 From: Alexandru GEORGESCU Date: Fri, 8 Mar 2019 12:11:23 +0200 Subject: [PATCH 3/4] Added PHPUnit 7 void hint. --- tests/AuthTest.php | 2 +- tests/EmbeddedRelationsTest.php | 2 +- tests/GeospatialTest.php | 4 ++-- tests/HybridRelationsTest.php | 4 ++-- tests/ModelTest.php | 2 +- tests/QueryBuilderTest.php | 2 +- tests/QueryTest.php | 4 ++-- tests/QueueTest.php | 2 +- tests/RelationsTest.php | 2 +- tests/SchemaTest.php | 2 +- tests/SeederTest.php | 2 +- tests/ValidationTest.php | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/AuthTest.php b/tests/AuthTest.php index 2b671fdd5..dad34e7a4 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -5,7 +5,7 @@ class AuthTest extends TestCase { - public function tearDown() + public function tearDown(): void { User::truncate(); DB::collection('password_reminders')->truncate(); diff --git a/tests/EmbeddedRelationsTest.php b/tests/EmbeddedRelationsTest.php index 5caae5b28..18e01557b 100644 --- a/tests/EmbeddedRelationsTest.php +++ b/tests/EmbeddedRelationsTest.php @@ -2,7 +2,7 @@ class EmbeddedRelationsTest extends TestCase { - public function tearDown() + public function tearDown(): void { Mockery::close(); diff --git a/tests/GeospatialTest.php b/tests/GeospatialTest.php index 2d646b337..b13ed46af 100644 --- a/tests/GeospatialTest.php +++ b/tests/GeospatialTest.php @@ -2,7 +2,7 @@ class GeospatialTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); @@ -43,7 +43,7 @@ public function setUp() ]); } - public function tearDown() + public function tearDown(): void { Schema::drop('locations'); } diff --git a/tests/HybridRelationsTest.php b/tests/HybridRelationsTest.php index 2223950ec..ade509067 100644 --- a/tests/HybridRelationsTest.php +++ b/tests/HybridRelationsTest.php @@ -2,7 +2,7 @@ class HybridRelationsTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); @@ -11,7 +11,7 @@ public function setUp() MysqlRole::executeSchema(); } - public function tearDown() + public function tearDown(): void { MysqlUser::truncate(); MysqlBook::truncate(); diff --git a/tests/ModelTest.php b/tests/ModelTest.php index b9cada8ac..906a39e68 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -8,7 +8,7 @@ class ModelTest extends TestCase { - public function tearDown() + public function tearDown(): void { User::truncate(); Soft::truncate(); diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index ac1479d26..0807b4ece 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -5,7 +5,7 @@ class QueryBuilderTest extends TestCase { - public function tearDown() + public function tearDown(): void { DB::collection('users')->truncate(); DB::collection('items')->truncate(); diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 2011305c2..de8589ebd 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -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']); @@ -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(); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 35be33f9a..f3ebc94f6 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -2,7 +2,7 @@ class QueueTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/RelationsTest.php b/tests/RelationsTest.php index 1e2aaa491..de3e0f222 100644 --- a/tests/RelationsTest.php +++ b/tests/RelationsTest.php @@ -2,7 +2,7 @@ class RelationsTest extends TestCase { - public function tearDown() + public function tearDown(): void { Mockery::close(); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index a04715d9d..5d63e28eb 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -2,7 +2,7 @@ class SchemaTest extends TestCase { - public function tearDown() + public function tearDown(): void { Schema::drop('newcollection'); } diff --git a/tests/SeederTest.php b/tests/SeederTest.php index 9581df3d3..61143e330 100644 --- a/tests/SeederTest.php +++ b/tests/SeederTest.php @@ -2,7 +2,7 @@ class SeederTest extends TestCase { - public function tearDown() + public function tearDown(): void { User::truncate(); } diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 16e31f4cf..267996420 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -2,7 +2,7 @@ class ValidationTest extends TestCase { - public function tearDown() + public function tearDown(): void { User::truncate(); } From 79cc254460b71b4778f56476c4e93c69f19cc8cc Mon Sep 17 00:00:00 2001 From: Alexandru GEORGESCU Date: Fri, 8 Mar 2019 12:18:53 +0200 Subject: [PATCH 4/4] Fixed typo. --- src/Jenssegers/Mongodb/Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index 80bc0c8fc..8180c7c83 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -1146,7 +1146,7 @@ protected function addUpdatedAtColumn(array $values) return array_merge( [$column => $this->model->freshTimestampString()], - $values, + $values ); }