| @@ 726-741 (lines=16) @@ | ||
| 723 | $relation->sync($prepared[$name]); |
|
| 724 | } |
|
| 725 | break; |
|
| 726 | case Relations\HasOne::class: |
|
| 727 | ||
| 728 | $related = $this->model->$name; |
|
| 729 | ||
| 730 | // if related is empty |
|
| 731 | if (is_null($related)) { |
|
| 732 | $related = $relation->getRelated(); |
|
| 733 | $related->{$relation->getForeignKeyName()} = $this->model->{$this->model->getKeyName()}; |
|
| 734 | } |
|
| 735 | ||
| 736 | foreach ($prepared[$name] as $column => $value) { |
|
| 737 | $related->setAttribute($column, $value); |
|
| 738 | } |
|
| 739 | ||
| 740 | $related->save(); |
|
| 741 | break; |
|
| 742 | case Relations\BelongsTo::class: |
|
| 743 | ||
| 744 | $parent = $this->model->$name; |
|
| @@ 742-764 (lines=23) @@ | ||
| 739 | ||
| 740 | $related->save(); |
|
| 741 | break; |
|
| 742 | case Relations\BelongsTo::class: |
|
| 743 | ||
| 744 | $parent = $this->model->$name; |
|
| 745 | ||
| 746 | // if related is empty |
|
| 747 | if (is_null($parent)) { |
|
| 748 | $parent = $relation->getRelated(); |
|
| 749 | } |
|
| 750 | ||
| 751 | foreach ($prepared[$name] as $column => $value) { |
|
| 752 | $parent->setAttribute($column, $value); |
|
| 753 | } |
|
| 754 | ||
| 755 | $parent->save(); |
|
| 756 | ||
| 757 | // When in creating, associate two models |
|
| 758 | if (!$this->model->{$relation->getForeignKey()}) { |
|
| 759 | $this->model->{$relation->getForeignKey()} = $parent->getKey(); |
|
| 760 | ||
| 761 | $this->model->save(); |
|
| 762 | } |
|
| 763 | ||
| 764 | break; |
|
| 765 | case Relations\MorphOne::class: |
|
| 766 | $related = $this->model->$name; |
|
| 767 | if (is_null($related)) { |
|