Filter out invalid columns before a save operation.

@param \Titon\Event\Event $event
@param \Titon\Db\Query $query
@param int|int[] $id
@param array $data
@return bool
180064
public function filterData(Event $event, Query $query, $id, array &$data) {
        if ($columns = $this->getSchema()->getColumns()) {
            $data = array_intersect_key($data, $columns);
        }

        return true;
    }
443880
public function removePictures($id, $data) {
		// find
		$model = $this->get($id);

		if ($model === null) {
			return new NotFound(['message' => 'Skill not found.']);
		}

		// pass remove to internal logic
		try {
			$this->doRemovePictures($model, $data);
		} catch (ErrorsException $e) {
			return new NotValid(['errors' => $e->getErrors()]);
		}

		// save and dispatch events
		$this->dispatch(SkillEvent::PRE_PICTURES_REMOVE, $model, $data);
		$this->dispatch(SkillEvent::PRE_SAVE, $model, $data);
		$rows = $model->save();
		$this->dispatch(SkillEvent::POST_PICTURES_REMOVE, $model, $data);
		$this->dispatch(SkillEvent::POST_SAVE, $model, $data);

		if ($rows > 0) {
			return Updated(['model' => $model]);
		}

		return NotUpdated(['model' => $model]);
	}
559741
public function write($id, $data): bool
    {
        return $this->handler->set($this->prepareId($id), $data, (int)$this->ttl);
    }
1289345
public function preSave(Event $event, Query $query, $id, array &$data) {
        $data[$this->getConfig($query->getType() === Query::UPDATE ? 'updateField' : 'createField')] = time();

        return true;
    }
851167
protected function triggerBeforeSave(
        $query, EntityInterface $entity, array $data
    ) {
        $save = $query instanceof Insert
            ? (new Save($entity, $data))
                ->setAction(Save::ACTION_BEFORE_INSERT)
            : (new Save($entity, $data))
                ->setAction(Save::ACTION_BEFORE_UPDATE);

        /** @var Save $save */
        return Orm::getEmitter($this->getEntityClassName())->emit($save);
    }
516880
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
    {
        $field = $this->getTrashField();
        $addCondition = true;

        $query->traverseExpressions(function ($expression) use (&$addCondition, $field) {
            if (!$addCondition) {
                return;
            }

            if ($expression instanceof IdentifierExpression
                && $expression->getIdentifier() === $field
            ) {
                $addCondition = false;

                return;
            }

            if (($expression instanceof Comparison || $expression instanceof BetweenExpression)
                && $expression->getField() === $field
            ) {
                $addCondition = false;
            }
        });

        if ($addCondition) {
            $query->andWhere($query->newExpr()->isNull($field));
        }
    }
1139421
public function saveById($id, $data)
    {
        $exists = !is_null($id);
        if (!$exists) {
            $id = $this->findAvailableIdByData($data);
        }
        parent::saveById($id, $data);
        return $id;
    }
497711
public function getEpisodesWithQuery(int $id, array $query): PaginatedResults
    {
        $json = $this->parent->performAPICallWithJsonResponse(
            'get',
            '/series/'.$id.'/episodes/query',
            ['query' => $query]
        );

        return new PaginatedResults(
            DataParser::parseDataArray($json, BasicEpisode::class),
            $this->parent->getLastLinks()
        );
    }
1296399
public function pub($id, $data)
    {
        if (!isset($this->events[$id])) {
            return false;
        }
        return $this->events[$id]->pub($data);
    }
857265
public function unsetDataEntry($id, $column)
    {
        if (!isset($this->data[$id])) {
            throw new InvalidArgumentException("Missing row with ID $id.");
        }
        unset($this->data[$id][$column], $this->modified[$id][$column]);
    }
1004156
protected function excludeOne(DataQuery $query)
    {
        $this->model = $query->applyRelation($this->relation);

        $predicate = sprintf("%s %s ?", $this->getDbName(), $this->getInverseOperator());
        $clause = [$predicate => $this->getDbFormattedValue()];

        return $this->aggregate ?
            $this->applyAggregate($query, $clause) :
            $query->where($clause);
    }
818612
public function apply(DataQuery $query)
    {
        if (($key = array_search('not', $this->modifiers)) !== false) {
            unset($this->modifiers[$key]);
            return $this->exclude($query);
        }
        if (is_array($this->value)) {
            return $this->applyMany($query);
        } else {
            return $this->applyOne($query);
        }
    }
254515
protected function performUpdate( Builder $query, array $options = [] )
	{
		$dirty = $this->getDirty();

		if ( count( $dirty ) > 0 )
		{
			// If the updating event returns false, we will cancel the update operation so
			// developers can hook Validation systems into their models and cancel this
			// operation if the model does not pass validation. Otherwise, we update.
			if ( $this->fireModelEvent( 'updating' ) === false )
			{
				return false;
			}

			// First we need to create a fresh query instance and touch the creation and
			// update timestamp on the model which are maintained by us for developer
			// convenience. Then we will just continue saving the model instances.
			if ( $this->timestamps && Arr::get( $options, 'timestamps', true ) )
			{
				$this->updateTimestamps();
			}

			// Once we have run the update operation, we will fire the "updated" event for
			// this model instance. This will allow developers to hook into these after
			// models are updated, giving them a chance to do any special processing.
			$dirty = $this->getDirty();

			if ( count( $dirty ) > 0 )
			{
				$numRows = $this->setKeysForSaveQuery( $query )->update( $dirty );

				$this->fireModelEvent( 'updated', false );
			}
		}

		return true;
	}
459220
public function apply(DataQuery $query)
    {
        if ($this->aggregate) {
            throw new InvalidArgumentException(sprintf(
                'Aggregate functions can only be used with comparison filters. See %s',
                $this->fullName
            ));
        }

        return parent::apply($query);
    }
1373520
public function save($model, $id, $data)
    {
        if (is_null($id)) { // insert
            $model->data = $this->sendCollectionRequest($model, $this->insert_mode, $data);
            $model->id = $model->data ? $model->data[$model->id_field] : null;
        } else { // update
            $model->data = $this->sendItemRequest($model, $id, $this->update_mode, $data);
            $model->id = $model->data ? $model->data[$model->id_field] : null;
        }

        return $model->id;
    }
882937
public function removeGroups($id, $data) {
		// find
		$model = $this->get($id);

		if ($model === null) {
			return new NotFound(['message' => 'Skill not found.']);
		}

		// pass remove to internal logic
		try {
			$this->doRemoveGroups($model, $data);
		} catch (ErrorsException $e) {
			return new NotValid(['errors' => $e->getErrors()]);
		}

		// save and dispatch events
		$this->dispatch(SkillEvent::PRE_GROUPS_REMOVE, $model, $data);
		$this->dispatch(SkillEvent::PRE_SAVE, $model, $data);
		$rows = $model->save();
		$this->dispatch(SkillEvent::POST_GROUPS_REMOVE, $model, $data);
		$this->dispatch(SkillEvent::POST_SAVE, $model, $data);

		if ($rows > 0) {
			return Updated(['model' => $model]);
		}

		return NotUpdated(['model' => $model]);
	}
1239294
public function beforeFind(Event $event, Query $query, $options, $primary) {
		$order = $query->clause('order');
		if (($order === null || !count($order)) && !empty($this->order)) {
			$query->order($this->order);
		}

		return $query;
	}