Removes a specific Model from a has-many relationship collection.

@api
@param   string  $key    The has-many relationship key.
@param   Model   $model  The model to remove from the collection.
@return  self
439057
public function remove($key, Model $model)
    {
        if (false === $this->isHasMany($key)) {
            return $this;
        }
        if (true === $this->isInverse($key)) {
            throw ModelException::cannotModifyInverse($this, $key);
        }
        $this->touch();
        $collection = $this->hasManyRelationships->get($key);
        $collection->remove($model);
        $this->doDirtyCheck();
        return $this;
    }
1058355
public function clear($key = null)
    {
        if (func_num_args() === 0) {
            $this->attributes = array();
        } elseif ($key === '$id') {
            throw new Exception('[Norm/Model] Restricting clear for $id.');
        } else {
            unset($this->attributes[$key]);
        }

        return $this;
    }
719492
public function detach($model, string $relation, Model $value)
    {
        if (! $model instanceof Model) {
            $model = $this->find($model);
        }

        $model->$relation()->detach($value);
    }
1354349
public static function deleteModel($model)
    {
        foreach(AnnotationManager::getPropertiesAnnotations(BeanFactory::getObjectClass($model), RelationBase::class) as $propertyName => $annotations)
        {
            if(null === $model[$propertyName])
            {
                continue;
            }
            $annotation = $annotations[0];
            Delete::parse($model, $propertyName, $annotation);
        }
    }
1227504
public function deleteModels(Models $models)
    {
        foreach ($models as $model) {
            $this->dispatchBeforeEvent($model, Event::DELETE);
        }

        $this->deleteAll()->executeModels($models);

        foreach ($models as $model) {
            $this->dispatchAfterEvent($model, Event::DELETE);
        }

        return $this;
    }
4860
public function setRelatedModel(Model $model) {
        $this->_relatedModel = $model;
        $this->setRelatedClass(get_class($model));

        return $this;
    }
675504
public function remove(Builder $query, Model $model)
    {
        $query = $query->getQuery();

        $query->wheres = (new Collection($query->wheres))->reject(function ($where) {
            return $this->isScopeConstraint($where);
        })->values()->all();
    }
798035
protected function detachRelatedModelsForOneOrMany($models, Relation $relation)
    {
        if ($models instanceof Model) {
            $models = new Collection([ $models ]);
        }

        if ( ! $this->allowDetachingOfOneOrMany() || ! count($models)) {
            return;
        }

        // If models that were previously attached but no longer should be
        // have nullable foreign keys, we can 'detach' them safely by dissociating
        // the reverse relation (if we know which relation that is, or nullifying the keys).

        // Get the foreign key(s) (id/type for morph, otherwise just the id)
        $foreignKeyNames = $this->getForeignKeyNamesForRelation($relation);

        $nullableKey = $this->explicitlyConfiguredForeignKeysNullable();
        if (null === $nullableKey) {
            $nullableKey = $this->hasNullableForeignKeys($relation, $models->first(), $foreignKeyNames);
        }

        if ($nullableKey) {
            // We can detach the models by setting their keys to null.
            foreach ($models as $model) {
                $this->setForeignKeysToNull($model, $relation, $foreignKeyNames);
            }

            return;
        }

        // If the related models do not have nullable keys, we cannot detach them
        // without deleting them. This must be explicitly configured to prevent accidental deletions.
        if ( ! $this->allowDeletionOfDetachedModels()) return;

        // We can delete the previously related models entirely
        foreach ($models as $model) {
            $model->delete();

            // todo: log?
        }
    }
1282476
public function link(Model $model) {
        $this->getLinked()->flush()->append($model);

        $this->getPrimaryModel()->set($this->getPrimaryForeignKey(), $model->id());

        return $this;
    }
919865
public function setModel(Model $model)
    {
        if (strpos($this->originalName, '.') !== false) {
            $parts = explode('.', $this->originalName);
            $name = array_pop($parts);

            while ($parts) {
                $part = array_shift($parts);
                $relation = $model->getAttribute($part);

                if ($relation instanceof Model) {
                    $model = $relation;
                    $this->setName($name);
                }
            }
        }

        return parent::setModel($model);
    }
842332
public function remove($key)
    {
        $method = 'remove'.$key;

        if (method_exists($this, $method)) {
            $this->$method();
        } else {
            unset($this->metas[$key]);
        }
    }
980829
public function remove(Builder $builder, Model $model)
    {
        $query      = $builder->getQuery();
        $column     = $model->getQualifiedPositionColumn();

        foreach ((array) $query->orders as $key => $order) {

            if ($order['column'] == $column) {
                $this->removeOrderBy($query, $key);
            }
        }
    }
1129534
public function clearCache(Model $model) {
        if ($this->_cached) {
            foreach ($this->_cached as $key => $value) {
                $this->deleteCache($model, $key);
            }
        }

        return Cache::clear(false, $this->settings[$model->alias]['cacheConfig']);
    }
357686
public function remove(Builder $builder, Model $model)
    {
        $query = $builder->getQuery();

        if (is_null($query->wheres)) {
            return;
        }

        $bindingKey = 0;

        $scopeConstraints = $this->getScopeConstraints($model);

        foreach ((array) $query->wheres as $key => $where) {
            $bindingsCount = $this->countBindings($where);

            if (in_array($where, $scopeConstraints)) {
                $this->removeWhere($query, $key);

                $this->removeBindings($query, $bindingKey, $bindingsCount);
            } else {
                $bindingKey += $bindingsCount;
            }
        }

        $query->wheres = array_values($query->wheres);
    }
1156222
protected function removeFromTreeByElement(Model $element)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($element);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        $this->removeFromTreeByLftRgt($connection, $tableName, $element->__lft, $element->__rgt);
    }
652437
public function removeKey($collection, $key) {
        return $this->driver->remove($collection, ['key' => (is_array($key) ? ['$in' => $key] : $key)]);
    }
906550
public function clearType($typeKey)
    {
        if (isset($this->models[$typeKey])) {
            unset($this->models[$typeKey]);
        }
        return $this;
    }