Get the field for the primary key.

@return  string  The name of the field
161873
public function key()
    {
        if (empty($this->key) && !empty($this->definition->primary)) {
            $keys = array_values(
                array_filter(
                    preg_split('~[\s,]+~', $this->definition->primary)
                )
            );
            $keys = array_map(
                function ($key) {
                    return Normalise::toVariable($key);
                },
                $keys
            );

            $this->key = count($keys) > 1 ? $keys : array_shift($keys);
        }

        if (empty($this->key) && $this->has('id')) {
            $this->key = 'id';
        }

        return $this->key;
    }
903878
protected function _mainFields()
    {
        $fields = $this->getConfig('mainTableFields');

        if ($fields) {
            return $fields;
        }

        $table = $this->_table;
        $fields = $table->getSchema()->columns();

        $this->setConfig('mainTableFields', $fields);

        return $fields;
    }
505747
public function getForeignKey()
    {
        if (is_null($this->foreignKey)) {
            $name = $this->getEntityDescriptor()->getTableName();
            $this->foreignKey = "{$this->normalizeFieldName($name)}_id";
        }
        return $this->foreignKey;
    }
42338
protected function getId()
    {
        if ($key = $this->manager->config('model_primary_key')) {
            return $this->manager->getInstance()->{$key};
        }

        return $this->manager->getInstance()->getKey();
    }
356477
public function getPrimaryKeyQuery() {
        if (!empty($this->primaryKey)
            && $this->hasAttribute($this->primaryKey)) {
            return static::query()->where($this->primaryKey,
                $this->getAttributeSource($this->primaryKey));
        }
        return false;
    }
879889
public function field_data()
	{
		$retval = array();

		for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
		{
			$retval[$i]			= new stdClass();
			$retval[$i]->name		= cubrid_field_name($this->result_id, $i);
			$retval[$i]->type		= cubrid_field_type($this->result_id, $i);
			$retval[$i]->max_length		= cubrid_field_len($this->result_id, $i);
			$retval[$i]->primary_key	= (int) (strpos(cubrid_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
		}

		return $retval;
	}
1322655
protected function _primaryKeyValue()
    {
        $fields = (array)$this->_table()->getPrimaryKey();
        $values = [];
        foreach ($fields as $field) {
            $values[] = $this->_deriveFieldFromContext($field);
        }

        if (count($values) === 1) {
            return $values[0];
        }

        return $values;
    }
444355
public function getPrimaryKey() {
        return $this->cache(__METHOD__, function() {
            $pk = $this->getConfig('primaryKey');
            $schema = $this->getSchema();

            if ($schema->hasColumn($pk)) {
                return $pk;
            }

            if ($pk = $schema->getPrimaryKey()) {
                return $pk['columns'][0];
            }

            return 'id';
        });
    }
80805
protected function guessForeignField()
    {
        // First we try to find a column that match the header pattern
        $columns = $this->getModelColumns();
        $names = Config::getHeadersPatterns();

        foreach ($columns as $column) {
            if (Helpers::strIs($names, $column)) {
                // At this point a column that match the header patter was found
                return $column;
            }
        }

        // At this point we know no column that match the header patters found.
        // Second we try to find a non-primary/non-foreign key column
        $primary = $this->getPrimaryKeyForForeignModel();
        $idPatterns = Config::getKeyPatterns();
        foreach ($columns as $column) {
            if ($column != $primary && !Helpers::strIs($idPatterns, $column)) {
                return $column;
            }
        }

        return $primary;
    }
194629
public static function primaryKey()
    {
        $model = static::buildNoInitModel();
        if (is_string($model->guidAttribute) && !empty($model->guidAttribute)) {
            return [$model->guidAttribute];
        }
        return [$model->idAttribute];
    }
1020020
public function getPrimaryKey()
    {
        // 取表结构
        $meta = $this->meta();

        // 逐个寻找主键
        foreach ($meta as $field) {
            if ($field['primaryKey']) {
                return $field['name'];
            }
        }
        return false;
    }
1204400
public function getId()
    {
        if (is_null($this->_id) && isset($this->object)) {
            $this->_id = $this->object->primaryKey;
        }

        return $this->_id;
    }
1356155
public function getFieldId()
    {
        $fieldId = $this->getAttribute('fieldId');
        if (null === $fieldId && null !== $this->field) {
            $fieldId = $this->$fieldId = $this->field->id;
        }

        return $fieldId;
    }
326679
final function KeyField()
    {
        if (!$this->keyField)
        {
            $fieldMappers = $this->FieldMappers();
            foreach ($fieldMappers as $name=>$mapper)
            {
                $keyInfo = $mapper->FieldInfo()->KeyInfo();
                if ($keyInfo && $keyInfo->IsPrimary())
                {
                    $this->keyField = $name;
                    break;
                }
            }
            if (!$this->keyField)
            {
                throw new \Exception('No (primary) key field found in ' . $this->TableName());
            }
        }
        return $this->keyField;
    }
201576
public function field_data()
	{
		$retval = array();
		for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
		{
			$retval[$i]			= new stdClass();
			$retval[$i]->name		= mysql_field_name($this->result_id, $i);
			$retval[$i]->type		= mysql_field_type($this->result_id, $i);
			$retval[$i]->max_length		= mysql_field_len($this->result_id, $i);
			$retval[$i]->primary_key	= (int) (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
		}

		return $retval;
	}
679343
protected function getPrimaryKeyName(Field $primaryField = null, $primaryKey = 'id')
    {
        return !is_null($primaryField) ? $primaryField->name : $primaryKey;
    }
1008446
public function getFields() {
        $fields = $this->_fields;

        if ($this->getJoins() && !$fields && $this->getType() === self::SELECT) {
            return array_keys($this->getRepository()->getSchema()->getColumns());
        }

        return $fields;
    }