|
4 | 4 | use MongoId;
|
5 | 5 | use MongoDate;
|
6 | 6 | use Carbon\Carbon;
|
| 7 | +use ReflectionMethod; |
7 | 8 | use Illuminate\Database\Eloquent\Relations\Relation;
|
8 | 9 | use Jenssegers\Mongodb\Eloquent\Builder;
|
9 | 10 | use Jenssegers\Mongodb\Relations\EmbedsOneOrMany;
|
@@ -233,22 +234,28 @@ public function getAttribute($key)
|
233 | 234 | // is handled by the parent method.
|
234 | 235 | if (method_exists($this, $camelKey))
|
235 | 236 | {
|
236 |
| - $relations = $this->$camelKey(); |
| 237 | + $method = new ReflectionMethod(get_called_class(), $camelKey); |
237 | 238 |
|
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()) |
241 | 241 | {
|
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) |
246 | 247 | {
|
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); |
248 | 258 | }
|
249 |
| - |
250 |
| - // Get the relation results. |
251 |
| - return $this->getRelationshipFromMethod($key, $camelKey); |
252 | 259 | }
|
253 | 260 | }
|
254 | 261 |
|
|
0 commit comments