|
3 | 3 | namespace Elasticquent; |
4 | 4 |
|
5 | 5 | use Exception; |
| 6 | +use ReflectionMethod; |
6 | 7 | use Illuminate\Database\Eloquent\Model; |
7 | 8 | use Illuminate\Database\Eloquent\Relations\Relation; |
8 | 9 |
|
@@ -685,25 +686,27 @@ public static function hydrateRecursive(Model $model, array $items, Relation $pa |
685 | 686 | * @param \Illuminate\Database\Eloquent\Model $model |
686 | 687 | */ |
687 | 688 | public static function loadRelationsAttributesRecursive(Model $model) |
688 | | - { |
689 | | - $attributes = $model->getAttributes(); |
690 | | - |
691 | | - foreach ($attributes as $key => $value) { |
692 | | - if (method_exists($model, $key)) { |
693 | | - $relation = $model->$key(); |
694 | | - if ($relation instanceof Relation) { |
695 | | - // Check if the relation field is single model or collections |
696 | | - if (!static::isMultiLevelArray($value)) { |
697 | | - $value = [$value]; |
698 | | - } |
699 | | - $models = static::hydrateRecursive($relation->getModel(), $value, $relation); |
700 | | - // Unset attribute before match relation |
701 | | - unset($model[$key]); |
702 | | - $relation->match([$model], $models, $key); |
703 | | - } |
| 689 | + { |
| 690 | + $attributes = $model->getAttributes(); |
| 691 | + foreach ($attributes as $key => $value) { |
| 692 | + if (method_exists($model, $key) ) { |
| 693 | + $refl = new ReflectionMethod($model, $key); |
| 694 | + if($refl->class != "Illuminate\Database\Eloquent\Model"){ |
| 695 | + $relation = $model->$key(); |
| 696 | + if ($relation instanceof Relation) { |
| 697 | + // Check if the relation field is single model or collections |
| 698 | + if (!static::isMultiLevelArray($value)) { |
| 699 | + $value = [$value]; |
704 | 700 | } |
| 701 | + $models = static::hydrateRecursive($relation->getModel(), $value, $relation); |
| 702 | + // Unset attribute before match relation |
| 703 | + unset($model[$key]); |
| 704 | + $relation->match([$model], $models, $key); |
| 705 | + } |
705 | 706 | } |
| 707 | + } |
706 | 708 | } |
| 709 | + } |
707 | 710 |
|
708 | 711 | /** |
709 | 712 | * Get the pivot attribute from a model. |
|
0 commit comments