|
8 | 8 | use Jenssegers\Mongodb\Relations\EmbedsMany; |
9 | 9 | use Jenssegers\Mongodb\Relations\EmbedsOne; |
10 | 10 | use Jenssegers\Mongodb\Relations\EmbedsOneOrMany; |
11 | | -use Jenssegers\Mongodb\Relations\MorphTo; |
12 | 11 | use MongoDB\BSON\ObjectID; |
13 | 12 | use MongoDB\BSON\UTCDateTime; |
14 | 13 | use ReflectionMethod; |
@@ -234,7 +233,19 @@ public function getAttribute($key) |
234 | 233 |
|
235 | 234 | // This attribute matches an embedsOne or embedsMany relation so we need |
236 | 235 | // to return the relation results instead of the interal attributes. |
237 | | - if ($relations instanceof EmbedsOneOrMany or $relations instanceof MorphTo) { |
| 236 | + if ($relations instanceof EmbedsOneOrMany) { |
| 237 | + // If the key already exists in the relationships array, it just means the |
| 238 | + // relationship has already been loaded, so we'll just return it out of |
| 239 | + // here because there is no need to query within the relations twice. |
| 240 | + if (array_key_exists($key, $this->relations)) { |
| 241 | + return $this->relations[$key]; |
| 242 | + } |
| 243 | + |
| 244 | + // Get the relation results. |
| 245 | + return $this->getRelationshipFromMethod($key, $camelKey); |
| 246 | + } |
| 247 | + |
| 248 | + if ($relations instanceof Relation) { |
238 | 249 | // If the key already exists in the relationships array, it just means the |
239 | 250 | // relationship has already been loaded, so we'll just return it out of |
240 | 251 | // here because there is no need to query within the relations twice. |
|
0 commit comments