Skip to content

Commit e2bc57c

Browse files
committed
Merge #383
1 parent e0a3cda commit e2bc57c

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use MongoId;
55
use MongoDate;
66
use Carbon\Carbon;
7+
use ReflectionMethod;
78
use Illuminate\Database\Eloquent\Relations\Relation;
89
use Jenssegers\Mongodb\Eloquent\Builder;
910
use Jenssegers\Mongodb\Relations\EmbedsOneOrMany;
@@ -233,22 +234,28 @@ public function getAttribute($key)
233234
// is handled by the parent method.
234235
if (method_exists($this, $camelKey))
235236
{
236-
$relations = $this->$camelKey();
237+
$method = new ReflectionMethod(get_called_class(), $camelKey);
237238

238-
// This attribute matches an embedsOne or embedsMany relation so we need
239-
// to return the relation results instead of the interal attributes.
240-
if ($relations instanceof EmbedsOneOrMany)
239+
// Ensure the method is not static to avoid conflicting with Eloquent methods.
240+
if ( ! $method->isStatic())
241241
{
242-
// If the key already exists in the relationships array, it just means the
243-
// relationship has already been loaded, so we'll just return it out of
244-
// here because there is no need to query within the relations twice.
245-
if (array_key_exists($key, $this->relations))
242+
$relations = $this->$camelKey();
243+
244+
// This attribute matches an embedsOne or embedsMany relation so we need
245+
// to return the relation results instead of the interal attributes.
246+
if ($relations instanceof EmbedsOneOrMany)
246247
{
247-
return $this->relations[$key];
248+
// If the key already exists in the relationships array, it just means the
249+
// relationship has already been loaded, so we'll just return it out of
250+
// here because there is no need to query within the relations twice.
251+
if (array_key_exists($key, $this->relations))
252+
{
253+
return $this->relations[$key];
254+
}
255+
256+
// Get the relation results.
257+
return $this->getRelationshipFromMethod($key, $camelKey);
248258
}
249-
250-
// Get the relation results.
251-
return $this->getRelationshipFromMethod($key, $camelKey);
252259
}
253260
}
254261

0 commit comments

Comments
 (0)