| @@ 123-138 (lines=16) @@ | ||
| 120 | * |
|
| 121 | * Overloaded to support relationships. |
|
| 122 | */ |
|
| 123 | public function clear($key) |
|
| 124 | { |
|
| 125 | if (true === $this->isHasOne($key)) { |
|
| 126 | return $this->setHasOne($key, null); |
|
| 127 | } |
|
| 128 | if (true === $this->isInverse($key)) { |
|
| 129 | throw ModelException::cannotModifyInverse($this, $key); |
|
| 130 | } |
|
| 131 | if (true === $this->isHasMany($key)) { |
|
| 132 | $collection = $this->hasManyRelationships->get($key); |
|
| 133 | $collection->clear(); |
|
| 134 | $this->doDirtyCheck(); |
|
| 135 | return $this; |
|
| 136 | } |
|
| 137 | return parent::clear($key); |
|
| 138 | } |
|
| 139 | ||
| 140 | /** |
|
| 141 | * Enables or disables has-many collection auto-initialization from the database. |
|
| @@ 360-376 (lines=17) @@ | ||
| 357 | * @param Model $model |
|
| 358 | * @return self |
|
| 359 | */ |
|
| 360 | public function push($key, Model $model) |
|
| 361 | { |
|
| 362 | if (true === $this->isHasOne($key)) { |
|
| 363 | return $this->setHasOne($key, $model); |
|
| 364 | } |
|
| 365 | if (false === $this->isHasMany($key)) { |
|
| 366 | return $this; |
|
| 367 | } |
|
| 368 | if (true === $this->isInverse($key)) { |
|
| 369 | throw ModelException::cannotModifyInverse($this, $key); |
|
| 370 | } |
|
| 371 | $this->touch(); |
|
| 372 | $collection = $this->hasManyRelationships->get($key); |
|
| 373 | $collection->push($model); |
|
| 374 | $this->doDirtyCheck(); |
|
| 375 | return $this; |
|
| 376 | } |
|
| 377 | ||
| 378 | /** |
|
| 379 | * Reloads the model from the database. |
|