Skip to content

Commit 02d427b

Browse files
author
Karl Pierce
committed
Override Model::isGuardableColumn() to return true, since we don't really have columns
1 parent 31d004b commit 02d427b

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,17 @@ protected function getRelationsWithoutParent()
473473
return $relations;
474474
}
475475

476+
/**
477+
* Checks if column exists on a table. As this is a document model, just return true. This also
478+
* prevents calls to non-existent function Grammar::compileColumnListing()
479+
* @param string $key
480+
* @return bool
481+
*/
482+
protected function isGuardableColumn($key)
483+
{
484+
return true;
485+
}
486+
476487
/**
477488
* @inheritdoc
478489
*/

tests/ModelTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,4 +722,11 @@ public function testTruncateModel()
722722

723723
$this->assertEquals(0, User::count());
724724
}
725+
726+
public function testGuardedModel()
727+
{
728+
Guarded::create(['var' => 'val']);
729+
730+
$this->assertEquals(1, Guarded::count());
731+
}
725732
}

tests/models/Guarded.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
5+
6+
class Guarded extends Eloquent
7+
{
8+
protected $connection = 'mongodb';
9+
protected $collection = 'guarded';
10+
protected $guarded = ['foobar'];
11+
}

0 commit comments

Comments
 (0)