| @@ 368-381 (lines=14) @@ | ||
| 365 | * @param Model $model The model to remove from the collection. |
|
| 366 | * @return self |
|
| 367 | */ |
|
| 368 | public function remove($key, Model $model) |
|
| 369 | { |
|
| 370 | if (false === $this->isHasMany($key)) { |
|
| 371 | return $this; |
|
| 372 | } |
|
| 373 | if (true === $this->isInverse($key)) { |
|
| 374 | throw ModelException::cannotModifyInverse($this, $key); |
|
| 375 | } |
|
| 376 | $this->touch(); |
|
| 377 | $collection = $this->hasManyRelationships->get($key); |
|
| 378 | $collection->remove($model); |
|
| 379 | $this->doDirtyCheck(); |
|
| 380 | return $this; |
|
| 381 | } |
|
| 382 | ||
| 383 | /** |
|
| 384 | * Sets a model property: an attribute value, a has-one model, or an entire has-many model collection. |
|
| @@ 463-475 (lines=13) @@ | ||
| 460 | * @param Model|null $model The model to relate. |
|
| 461 | * @return self |
|
| 462 | */ |
|
| 463 | protected function setHasOne($key, Model $model = null) |
|
| 464 | { |
|
| 465 | if (true === $this->isInverse($key)) { |
|
| 466 | throw ModelException::cannotModifyInverse($this, $key); |
|
| 467 | } |
|
| 468 | if (null !== $model) { |
|
| 469 | $this->validateRelSet($key, $model->getType()); |
|
| 470 | } |
|
| 471 | $this->touch(); |
|
| 472 | $this->hasOneRelationships->set($key, $model); |
|
| 473 | $this->doDirtyCheck(); |
|
| 474 | return $this; |
|
| 475 | } |
|
| 476 | ||
| 477 | /** |
|
| 478 | * Validates that the model type (from a Model or Collection instance) can be set to the relationship field. |
|