@@ 400-413 (lines=14) @@ | ||
397 | * @param Model $model The model to remove from the collection. |
|
398 | * @return self |
|
399 | */ |
|
400 | public function remove($key, Model $model) |
|
401 | { |
|
402 | if (false === $this->isHasMany($key)) { |
|
403 | return $this; |
|
404 | } |
|
405 | if (true === $this->isInverse($key)) { |
|
406 | throw ModelException::cannotModifyInverse($this, $key); |
|
407 | } |
|
408 | $this->touch(); |
|
409 | $collection = $this->hasManyRelationships->get($key); |
|
410 | $collection->remove($model); |
|
411 | $this->doDirtyCheck(); |
|
412 | return $this; |
|
413 | } |
|
414 | ||
415 | /** |
|
416 | * {@inheritdoc} |
|
@@ 525-537 (lines=13) @@ | ||
522 | * @param Model|null $model The model to relate. |
|
523 | * @return self |
|
524 | */ |
|
525 | protected function setHasOne($key, Model $model = null) |
|
526 | { |
|
527 | if (true === $this->isInverse($key)) { |
|
528 | throw ModelException::cannotModifyInverse($this, $key); |
|
529 | } |
|
530 | if (null !== $model) { |
|
531 | $this->validateRelSet($key, $model->getType()); |
|
532 | } |
|
533 | $this->touch(); |
|
534 | $this->hasOneRelationships->set($key, $model); |
|
535 | $this->doDirtyCheck(); |
|
536 | return $this; |
|
537 | } |
|
538 | ||
539 | /** |
|
540 | * Sets a relationship value. |