Returns an array of only the persistent fields of {@link $model}

@param ModelObject $model The modelObject to analyze

@return array An array with persistent field names as keys with their values
5295
public function modelToPersistentArray(ModelObject $model)
    {
        $persistent = array_intersect_key($model->toArray(), array_flip($model->getPersistentFields()));

        return $persistent;
    }
350131
public function referencing(Model $model)
    {
        $references = [];

        // TODO: SchemaManager should do this
        foreach ($this->schemas as $schema) {
            $references = array_merge($references, $schema->referencing($model->getBlueprint()));
        }

        // TODO: ModelManager should do this
        foreach ($references as &$related) {
            $blueprint = $related['blueprint'];
            $related['model'] = $model->getBlueprint()->is($blueprint->schema(), $blueprint->table())
                ? $model
                : $this->makeModel($blueprint->schema(), $blueprint->table(), false);
        }

        return $references;
    }
169131
private function getForeignKeyForNewAssociation(Model $model)
	{
		$this->setKeys($model);
		$primaryKey = Inflector::instance()->variablize($this->foreignKey[0]);

		return array(
			$primaryKey => $model->id,
		);
	}
681126
protected function getScopeConstraints(Model $model)
    {
        $builder = $model->newQueryWithoutScopes();

        $this->apply($builder, $model);

        return (array) $builder->getQuery()->wheres;
    }
1338135
protected function _getSubTree(Model $model, $id = null) {
		$result = [];
		$parentField = $this->_getBehaviorConfig($model, 'parent');
		$leftField = $this->_getBehaviorConfig($model, 'left');
		if (($parentField === null) || ($leftField === null)) {
			return $result;
		}

		$conditions = [
			$model->alias . '.' . $parentField => null
		];
		if (!empty($id)) {
			$conditions[$model->alias . '.' . $parentField] = (int)$id;
		}
		if ($model->Behaviors->Tree->settings[$model->alias]['scope'] !== '1 = 1') {
			$conditions[] = $model->Behaviors->Tree->settings[$model->alias]['scope'];
		}

		$fields = [
			$model->alias . '.' . $model->primaryKey,
		];
		$order = [
			$model->alias . '.' . $leftField => 'asc'
		];
		$model->recursive = -1;
		$data = $model->find('list', compact('conditions', 'fields', 'order'));
		if (!empty($data)) {
			$result = array_keys($data);
		}

		return $result;
	}
1335297
public static function extractModelAndKeys($model, array $keys = null)
    {
        if (! is_null($keys)) {
            if (is_string($model)) {
                $model = new $model;
            }

            return [$model, $keys];
        }

        if ($model instanceof Model) {
            return [$model, [$model->getKey()]];
        }

        if ($model instanceof Collection) {
            $keys = $model->map(function ($model) {
                return $model->getKey();
            });

            return [$model->first(), $keys];
        }
    }
1020544
public static function getNames($model) : Collection
    {
        if (is_object($model)) {
            $guardName = $model->guard_name ?? null;
        }

        if (! isset($guardName)) {
            $class = is_object($model) ? get_class($model) : $model;

            $guardName = (new \ReflectionClass($class))->getDefaultProperties()['guard_name'] ?? null;
        }

        if ($guardName) {
            return collect($guardName);
        }

        return collect(config('auth.guards'))
            ->map(function ($guard) {
                if (! isset($guard['provider'])) {
                    return;
                }

                return config("auth.providers.{$guard['provider']}.model");
            })
            ->filter(function ($model) use ($class) {
                return $class === $model;
            })
            ->keys();
    }
1264853
public static function getModelBehaviorAttributes($model)
    {
        $behaviorAttributes = [];
        $blameableAttributes = [];
        foreach ($model->behaviors() as $behaviorName => $behaviorOptions) {
            if (!is_array($behaviorOptions)) {
                continue;
            }
            switch ($behaviorOptions['class']) {
                case \netis\crud\db\SortableBehavior::className():
                    $behaviorAttributes[] = $behaviorOptions['attribute'];
                    break;
                case \netis\crud\db\ToggableBehavior::className():
                    if (isset($behaviorOptions['disabledAttribute'])) {
                        $behaviorAttributes[] = $behaviorOptions['disabledAttribute'];
                    }
                    if (isset($behaviorOptions['enabledAttribute'])) {
                        $behaviorAttributes[] = $behaviorOptions['enabledAttribute'];
                    }
                    break;
                case \netis\crud\db\BlameableBehavior::className():
                    if (isset($behaviorOptions['createdByAttribute'])) {
                        $behaviorAttributes[] = $behaviorOptions['createdByAttribute'];
                        $blameableAttributes[] = $behaviorOptions['createdByAttribute'];
                    }
                    if (isset($behaviorOptions['updatedByAttribute'])) {
                        $behaviorAttributes[] = $behaviorOptions['updatedByAttribute'];
                        $blameableAttributes[] = $behaviorOptions['updatedByAttribute'];
                    }
                    break;
                case \netis\crud\db\TimestampBehavior::className():
                    if (isset($behaviorOptions['createdAtAttribute'])) {
                        $behaviorAttributes[] = $behaviorOptions['createdAtAttribute'];
                    }
                    if (isset($behaviorOptions['updatedAtAttribute'])) {
                        $behaviorAttributes[] = $behaviorOptions['updatedAtAttribute'];
                    }
                    break;
            }
        }
        return [$behaviorAttributes, $blameableAttributes];
    }
133625
public function persist($model)
    {
        $class    = $this->manager->getClassMetadata(get_class($model));
        $managers = $class->getFieldManagerNames();
        $pool     = $this->manager->getPool();

        $managerName = $class->getManagerReferenceGenerator();
        $referenceModel = call_user_func(array($model, 'get' . ucfirst($managerName)));

        $pool->getManager($managerName)->persist($referenceModel);

        unset($managers[array_search($managerName, $managers)]);

        $this->models->attach($model, $managers);
    }
456219
public function getList(Model $model) {
        return $model->find('list', array(
            'order' => array($model->alias . '.' . $model->displayField => 'ASC'),
            'cache' => $model->alias . '::getList',
            'cacheExpires' => $this->getExpiration($model)
        ));
    }
171822
public function getInstanceValueForFields(Model $modelInstance, $fields)
    {
        $values = [];
        /** @var $field Field */
        foreach ($fields as $field) {
            $val = $modelInstance->{$field->getAttrName()};
            if (!$val) {
                continue;
            }
            $values[] = $val;
        }

        return $values;
    }
1276996
public function getFields($objectName)
    {
        $fieldConfigurations = array();
        $modelConfiguration = $this->getModelConfiguration($objectName);
        if (is_array($modelConfiguration)) {
            $fieldConfigurations = $modelConfiguration['fields'];
        }

        return $fieldConfigurations;
    }
595110
public function endObject(Model $model)
    {
        $this->objects[] = $this->dumpObject($model);
        $this->_fields = null;
    }
1133400
public function getModelCallbacks(Model $model, $scope = '*') {
        $callbacks = array();
        $models = Configure::read('Admin.modelCallbacks');

        if (isset($models[$model->qualifiedName])) {
            foreach ($models[$model->qualifiedName] as $method => $options) {
                if (is_string($options)) {
                    $options = array('title' => $options, 'access' => 'update', 'scope' => '*');
                } else {
                    $options = $options += array('access' => 'update', 'scope' => '*');
                }

                if ($options['scope'] !== $scope) {
                    continue;
                }

                if ($this->hasAccess($model->qualifiedName, $options['access'])) {
                    $callbacks[$method] = __d('admin', $options['title'], $model->singularName);
                }
            }
        }

        return $callbacks;
    }
902043
protected function collectColumns(Model $model = null)
    {
        if (!$model) {
            return new MutableCollection([]);
        }

        $pk = $model->getKeyName();

        $fillable = array_merge(
            is_array($pk) ? $pk : [$pk],
            $model->getFillable()
        );
        $hidden = $model->getHidden();

        if ($model instanceof Translatable && method_exists($model, 'getTranslatedAttributes')) {
            $fillable = array_merge($fillable, $model->getTranslatedAttributes());
            $hidden = array_merge($hidden, $model->getTranslationModel()->getHidden());
        }

        $fillable = array_unique(array_diff($fillable, $hidden));

        /**
         * Create collection.
         */
        $elements = new MutableCollection($fillable);

        if ($this->includeDateColumns && count($dates = $model->getDates())) {
            // allow setting specific timestamp: created_at
            if (is_string($this->includeDateColumns)) {
                $dates = array_intersect($dates, [$this->includeDateColumns]);

                $elements = $elements->merge($dates);
            } else {
                // add timestamps group
                $elements->group('dates', function (Group $group) use ($dates) {
                    $group->merge($dates);

                    return $group;
                });
            }
        }

        return $elements->build(
            new GridDecorator($model)
        );
    }
1008522
protected function getTimestampFields($model)
    {
        try {
            $baseModel = new ReflectionClass($model);
            $timestampFields = [
                'created_at' => $baseModel->getConstant('CREATED_AT'),
                'updated_at' => $baseModel->getConstant('UPDATED_AT'),
                'deleted_at' => $baseModel->getConstant('DELETED_AT'),
            ];
        } catch (Exception $e) {
            echo 'baseModel: '.$model.' not found'.LF;
            $timestampFields = [
                'created_at' => 'created_at',
                'updated_at' => 'updated_at',
                'deleted_at' => 'deleted_at',
            ];
        }

        return $timestampFields;
    }
336901
protected function getCasts(Model $model)
    {
        $class = get_class($model);

        if (!isset($this->castsCache[$class])) {
            $this->castsCache[$class] = Cheat::get($model, 'casts');
        }

        return $this->castsCache[$class];
    }