@@ 116-131 (lines=16) @@ | ||
113 | * |
|
114 | * Overloaded to support relationships. |
|
115 | */ |
|
116 | public function clear($key) |
|
117 | { |
|
118 | if (true === $this->isHasOne($key)) { |
|
119 | return $this->setHasOne($key, null); |
|
120 | } |
|
121 | if (true === $this->isInverse($key)) { |
|
122 | throw ModelException::cannotModifyInverse($this, $key); |
|
123 | } |
|
124 | if (true === $this->isHasMany($key)) { |
|
125 | $collection = $this->hasManyRelationships->get($key); |
|
126 | $collection->clear(); |
|
127 | $this->doDirtyCheck(); |
|
128 | return $this; |
|
129 | } |
|
130 | return parent::clear($key); |
|
131 | } |
|
132 | ||
133 | /** |
|
134 | * Enables or disables has-many collection auto-initialization from the database. |
|
@@ 345-361 (lines=17) @@ | ||
342 | * @param Model $model |
|
343 | * @return self |
|
344 | */ |
|
345 | public function push($key, Model $model) |
|
346 | { |
|
347 | if (true === $this->isHasOne($key)) { |
|
348 | return $this->setHasOne($key, $model); |
|
349 | } |
|
350 | if (false === $this->isHasMany($key)) { |
|
351 | return $this; |
|
352 | } |
|
353 | if (true === $this->isInverse($key)) { |
|
354 | throw ModelException::cannotModifyInverse($this, $key); |
|
355 | } |
|
356 | $this->touch(); |
|
357 | $collection = $this->hasManyRelationships->get($key); |
|
358 | $collection->push($model); |
|
359 | $this->doDirtyCheck(); |
|
360 | return $this; |
|
361 | } |
|
362 | ||
363 | /** |
|
364 | * Reloads the model from the database. |