Skip to content

Commit b24f5d7

Browse files
author
Pooya Parsa
committed
null MorphTo relations
1 parent 0fc7c47 commit b24f5d7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Jenssegers\Mongodb\Relations\EmbedsMany;
99
use Jenssegers\Mongodb\Relations\EmbedsOne;
1010
use Jenssegers\Mongodb\Relations\EmbedsOneOrMany;
11+
use Jenssegers\Mongodb\Relations\MorphTo;
1112
use MongoDB\BSON\ObjectID;
1213
use MongoDB\BSON\UTCDateTime;
1314
use ReflectionMethod;
@@ -233,11 +234,11 @@ public function getAttribute($key)
233234

234235
// This attribute matches an embedsOne or embedsMany relation so we need
235236
// to return the relation results instead of the interal attributes.
236-
if ($relations instanceof EmbedsOneOrMany) {
237+
if ($relations instanceof EmbedsOneOrMany or $relations instanceof MorphTo) {
237238
// If the key already exists in the relationships array, it just means the
238239
// relationship has already been loaded, so we'll just return it out of
239240
// here because there is no need to query within the relations twice.
240-
if (array_key_exists($key, $this->relations)) {
241+
if (array_key_exists($key, $this->relations) && $this->relations[$key] != null) {
241242
return $this->relations[$key];
242243
}
243244

0 commit comments

Comments
 (0)