Skip to content

Commit 9442df1

Browse files
committed
Fix truncate on models
According to docs array or object might be returned, so we need to add options. See https://docs.mongodb.com/php-library/v1.5/reference/method/MongoDBCollection-drop/
1 parent ef147ea commit 9442df1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: src/Jenssegers/Mongodb/Query/Builder.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,11 @@ public function from($collection, $as = null)
700700
*/
701701
public function truncate()
702702
{
703-
$result = $this->collection->drop();
703+
$options = [
704+
'typeMap' => ['root' => 'object', 'document' => 'object'],
705+
];
706+
707+
$result = $this->collection->drop($options);
704708

705709
return (1 == (int) $result->ok);
706710
}

Diff for: tests/QueryBuilderTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ public function testDelete()
175175
public function testTruncate()
176176
{
177177
DB::collection('users')->insert(['name' => 'John Doe']);
178-
DB::collection('users')->truncate();
178+
$result = DB::collection('users')->truncate();
179+
$this->assertEquals(1, $result);
179180
$this->assertEquals(0, DB::collection('users')->count());
180181
}
181182

0 commit comments

Comments
 (0)