Get an array containing the key and value of the foreign key for the association

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

		return array(
			$primaryKey => $model->id,
		);
	}
769457
protected function _getAliases(Model $Model) {
		$aliases = array_merge(array(
			//$Model->name,
			$Model->alias
				), $this->config[$Model->alias]['aliases']
		);

		foreach ($Model->associations() as $associationType) {
			foreach ($Model->$associationType as $associationKey => $association) {
				if ($association['className'] === $Model->name) {
					$aliases[] = $associationKey;
				}
			}
		}

		return $aliases;
	}
913330
public function getFields($model)
    {
        //
        $table = $this->getTable($model);

        //
        $sql = "DESC `{$table}`";

        //
        $results = $this->getResults($sql);

        //
        $fields = [];

        //
        foreach ($results as $field) {
            $fields[] = $field['Field'];
        }

        //
        return $fields;
    }
615914
public function retrieve(Model $model, $source)
    {
        return [
            'from' => parent::retrieve($model, $this->getAttributeFrom()),
            'to'   => parent::retrieve($model, $this->getAttributeTo()),
        ];
    }
1190334
public function getRelationalDataAndModels($model, $desired_relation)
    {
        // $relations = $model->getRelations();
        $relation = $this->trimCommonRelationEndings($desired_relation);
        // Grab all the model relationships that don't return as a collection
        if (method_exists($model, $relation)) {
            // We have our relation, return it
            return $this->getResolvedRelationship($model, $relation);
        } elseif (method_exists($model, $relation.'s')) {
            // We have our relations, return it
            return $this->getResolvedRelationship($model, $relation.'s');
        } elseif (method_exists($model, $relation.'s')) {
            return $this->getResolvedRelationship($model, $relation.'s');
        }
        // don't return because clearly, nothing matches what we need.
    }
990015
public static function model($model, $value, $key = 'id')
    {
        if (! $model instanceof Builder) {
            $model = $model::query();
        }

        return $model->get()->map(function ($model) use ($value, $key) {
            return [
                'value' => $model->{$key},
                'label' => $model->{$value},
            ];
        });
    }
1049648
public function getModelLinks(Model $model) {
        $models = Configure::read('Admin.modelLinks');

        if (isset($models[$model->qualifiedName])) {
            return $models[$model->qualifiedName];
        }

        return array();
    }
435294
private function getRelationshipType($model)
    {
        // Poke method to check the type of instance
        $class = get_class($this->{$model}());
        $reflection = new ReflectionClass($class);

        return (in_array($reflection->getShortName(), ['BelongsTo', 'HasOne', 'MorphOne', 'MorphTo'])) ? 'one' : 'many';
    }
628502
protected static function getModelsForRelation($model, $relationKey)
    {
        if (!method_exists($model, $relationKey)) {
            throw new Exception(
                    'Relation "' . $relationKey . '" does not exist in model',
                    static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
                    BaseResponse::HTTP_INTERNAL_SERVER_ERROR
                );
        }
        $relationModels = $model->{$relationKey};
        if (is_null($relationModels)) {
            return null;
        }

        if (! $relationModels instanceof Collection) {
            return [ $relationModels ];
        }

        return $relationModels;
    }
203622
protected function showDatabaseFields(Model $model)
    {
        $this->title("Table {$model->getTable()} :");

        if ( ! $this->db->isConnected()) {
            $this->warn("Not Connected to databse, please check your connection config\r");
        } else {
            $fields = $this->db->getFields($model->getTable());
            $headers = ['name', 'type', 'null', 'length', 'unsigned', 'autoincrement', 'primary_key', 'foreign_key'];

            $this->table($headers, $fields->toArray());
        }
    }
1111196
protected function getModelPrimaryKeyString($model)
    {
        return is_array($model->getPrimaryKey()) ? implode('-', $model->getPrimaryKey()) : $model->getPrimaryKey();
    }
535304
protected function getTableAndDatabase($model)
    {
        $table = $model->getConnection()->getTablePrefix() . $model->getTable();

        $database = null;

        if (strpos($table, '.')) {
            list($database, $table) = explode('.', $table);
        }

        return [$table, $database];
    }
690726
protected function getModelFields(\atk4\data\Model $model)
    {
        $fields = [];
        foreach ($model->elements as $f) {
            if (!$f instanceof \atk4\data\Field) {
                continue;
            }

            if ($f->isEditable() || $f->isVisible()) {
                $fields[] = $f->short_name;
            }
        }

        return $fields;
    }
667926
public function belongsTo($model, $options = array())
    {
        if (isset($this->_relationsCache[$model])) {
            return $this->_relationsCache[$model];
        }

        $options = static::getRelationInfo($model, $options);

        if (!isset($options['localKey'])) {
            $options['localKey'] = Inflector::foreignKey($model);
        }

        if (!isset($options['foreignKey'])) {
            $options['foreignKey'] = $options['model']::primaryKey();
        }

        return $this->_relationsCache[$model] = $options['model']::select()
            ->where("{$options['foreignKey']} = ?", $this->{$options['localKey']})
            ->fetch();
    }
1138883
protected function exposedRelationsFromRequest($model = null)
    {
        $exposedRelations = static::$exposedRelations;

        // if no relations are to be included by request
        if (count($this->request->include) == 0) {
            // and if we have a model
            if ($model !== null && $model instanceof Model) {
                // then use the relations exposed by default
                $exposedRelations = array_intersect($exposedRelations, $model->defaultExposedRelations());
                $model->setExposedRelations($exposedRelations);
                return $exposedRelations;
            }

        }

        $exposedRelations = array_intersect($exposedRelations, $this->request->include);
        if ($model !== null && $model instanceof Model) {
            $model->setExposedRelations($exposedRelations);
        }

        return $exposedRelations;
    }
1204546
protected function serializeModel($model)
    {
        list ($fields, $expand) = $this->getRequestedFields();
        return $model->toArray($fields, $expand);
    }
48841
private function queryAttributes(Model $model)
    {
        $data = [
            'user_id'    => user()->id,
            'namespace'  => get_class($model),
            'foreign_id' => $model->id
        ];
        (is_null($this->field)) ? array_set($data, 'field_class', get_called_class()) : array_set($data, 'field_id', $this->field->id);
        return $data;
    }