|
13 | 13 | use DateTime;
|
14 | 14 | use MongoId;
|
15 | 15 | use MongoDate;
|
| 16 | +use ReflectionMethod; |
16 | 17 |
|
17 | 18 | abstract class Model extends \Jenssegers\Eloquent\Model {
|
18 | 19 |
|
@@ -250,23 +251,32 @@ public function getAttribute($key)
|
250 | 251 | // is handled by the parent method.
|
251 | 252 | if (method_exists($this, $camelKey))
|
252 | 253 | {
|
253 |
| - $relations = $this->$camelKey(); |
| 254 | + $method = new ReflectionMethod(get_called_class(), $camelKey); |
254 | 255 |
|
255 |
| - // This attribute matches an embedsOne or embedsMany relation so we need |
256 |
| - // to return the relation results instead of the interal attributes. |
257 |
| - if ($relations instanceof EmbedsOneOrMany) |
| 256 | + // Ensure the method is not static to avoid conflicting with 'search methods'. |
| 257 | + // e.g. find, in, all, where, etc... |
| 258 | + if(!$method->isStatic()) |
258 | 259 | {
|
259 |
| - // If the key already exists in the relationships array, it just means the |
260 |
| - // relationship has already been loaded, so we'll just return it out of |
261 |
| - // here because there is no need to query within the relations twice. |
262 |
| - if (array_key_exists($key, $this->relations)) |
| 260 | + $relations = $this->$camelKey(); |
| 261 | + |
| 262 | + // This attribute matches an embedsOne or embedsMany relation so we need |
| 263 | + // to return the relation results instead of the interal attributes. |
| 264 | + if ($relations instanceof EmbedsOneOrMany) |
263 | 265 | {
|
264 |
| - return $this->relations[$key]; |
| 266 | + // If the key already exists in the relationships array, it just means the |
| 267 | + // relationship has already been loaded, so we'll just return it out of |
| 268 | + // here because there is no need to query within the relations twice. |
| 269 | + if (array_key_exists($key, $this->relations)) |
| 270 | + { |
| 271 | + return $this->relations[$key]; |
| 272 | + } |
| 273 | + |
| 274 | + // Get the relation results. |
| 275 | + return $this->getRelationshipFromMethod($key, $camelKey); |
265 | 276 | }
|
266 | 277 |
|
267 |
| - // Get the relation results. |
268 |
| - return $this->getRelationshipFromMethod($key, $camelKey); |
269 | 278 | }
|
| 279 | + |
270 | 280 | }
|
271 | 281 |
|
272 | 282 | return parent::getAttribute($key);
|
|
0 commit comments