Gets the name of the foreign model's primary key.

@return string
351152
public function getPrimaryKeyForForeignModel()
    {
        $model = $this->getForeignModelInstance();

        if ($this->isModel($model)) {
            return $model->getKeyName();
        }

        return $this->getKeyNameFromResource() ?: 'id';
    }
104030
public String getReverseRelationshipName()
    {
        String ret = "";
        if (tableAB == null)
        {
            if (multipleRelationsBetweenTables)  // foreignKey will be non-null since it applies only to one-to-X relation
            {
                ret = concatenateColumnNames(this);
                ret = ret.substring(1) + "_"; // remove leading _ and add trailing _.
            }

            ret += StringUtility.firstLetterToLower(tableA.getClassName());
        }
        else
        {
            ForeignKey[] fks = tableAB.getForeignKeys().values().toArray(new ForeignKey[2]);
            ret = ForeignKey.concatenateColumnNames(fks[0]).substring(1);
        }
        String multiplicity = getTableAMultiplicity();
        if (!multiplicity.equals("one"))
            ret = StringUtility.englishPluralize(ret);

        return ret;
    }
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;
    }
597615
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey)
    {
        $def = '';
        if ($foreignKey->getConstraint()) {
            $def .= ' CONSTRAINT ' . $this->quoteColumnName($foreignKey->getConstraint());
        } else {
            $columnNames = [];
            foreach ($foreignKey->getColumns() as $column) {
                $columnNames[] = $this->quoteColumnName($column);
            }
            $def .= ' FOREIGN KEY (' . implode(',', $columnNames) . ')';
            $refColumnNames = [];
            foreach ($foreignKey->getReferencedColumns() as $column) {
                $refColumnNames[] = $this->quoteColumnName($column);
            }
            $def .= ' REFERENCES ' . $this->quoteTableName($foreignKey->getReferencedTable()->getName()) . ' (' . implode(',', $refColumnNames) . ')';
            if ($foreignKey->getOnDelete()) {
                $def .= ' ON DELETE ' . $foreignKey->getOnDelete();
            }
            if ($foreignKey->getOnUpdate()) {
                $def .= ' ON UPDATE ' . $foreignKey->getOnUpdate();
            }
        }

        return $def;
    }
1317003
public function primary()
    {
        $key = $this->tableHasPrimary()->getPrimaryKey();
        $message = "The column {$this->name} is not a primary key.";

        return $this->assertTrue(in_array($this->name, $key->getColumns()), $message)
                    ->assertTrue($key->isPrimary())
                    ->assertTrue($key->isUnique());
    }
1167231
function GetPrimaryKeyName()
    {
        $fms = $this->_phreezer->GetFieldMaps(get_class($this));
        foreach ($fms as $fm)
        {
            if ($fm->IsPrimaryKey)
            {
				return $fm->PropertyName;
			}
        }

		/*
		print "<pre>";
		$this->Data = "";
		$this->_phreezer = null;
		$this->_cache = null;
		print_r($this);

		print_r($fms);
		die();
		*/

		throw new Exception("No Primary Key found for " . get_class($this));
    }
309261
public static function getMainField()
    {
        //
        $attribute = 'MainField';

        // retrieve value from class setting definition
        if (!static::hasClassAttribute($attribute)) {
            $mainField = null;

            //
            $schema = static::getSchema();

            //
            foreach ($schema as $field => &$attributes) {
                if ($attributes['Key'] == 'PRI') {
                    continue;
                }

                //
                $mainField = $field;

                //
                break;
            }

            // store as setting for future request
            static::setClassAttribute($attribute, $mainField);
        }

        // return primary key field name
        return static::getClassAttribute($attribute);
    }
1272795
public function getForeignKey(): string
	{
		if(empty($this->foreignKeyName))
		{
			$this->foreignKeyName = Str::camel2underscored($this->getClassShortName()) . '_id';
		}

		return $this->foreignKeyName;
	}
616527
public function getQualifiedKeyName()
    {
        $keyName = $this->getKeyName();

        if (is_array($keyName)) { //Check for multi-columns relationship
            $keys = [];

            foreach ($keyName as $key) {
                $keys[] = $this->getTable().$key;
            }

            return $keys;
        }

        return $this->getTable().'.'.$keyName;
    }
694888
private function getName($foreignKey, $ignoreForeignKeyNames) {
		if ($ignoreForeignKeyNames or $this->isDefaultName($foreignKey)) {
			return null;
		}
		return $foreignKey->getName();
	}
1095144
public function getPrimaryKeyValue()
    {
        $primaryKey = $this->getPrimaryKey();
        if (isset($this->$primaryKey)) {
            return $this->$primaryKey;
        } else {
            return null;
        }
    }
707730
public function getQualifiedParentKeyName()
    {
        if (is_array($this->localKey)) { //Check for multi-columns relationship
            return array_map(function ($k) {
                return $this->parent->getTable().'.'.$k;
            }, $this->localKey);
        } else {
            return $this->parent->getTable().'.'.$this->localKey;
        }
    }
614074
public function getPrimaryKey()
    {
        $pk = array();
        foreach ($this->columnList as $col) {
            if ($col->isPrimaryKey()) {
                $pk[] = $col;
            }
        }

        return $pk;
    }
656586
public function getQualifiedForeignKey()
    {
        if (is_array($this->foreignKey)) { //Check for multi-columns relationship
            return array_map(function ($k) {
                return $this->child->getTable().'.'.$k;
            }, $this->foreignKey);
        } else {
            return $this->child->getTable().'.'.$this->foreignKey;
        }
    }
549345
protected function getOtherKey()
    {
        if ($this->otherKey) {
            return $this->otherKey;
        }

        if (is_callable([$this->form->model(), $this->column]) &&
            ($relation = $this->form->model()->{$this->column}()) instanceof BelongsToMany
        ) {
            /* @var BelongsToMany $relation */
            $fullKey = $relation->getQualifiedRelatedPivotKeyName();

            return $this->otherKey = substr($fullKey, strpos($fullKey, '.') + 1);
        }

        throw new \Exception('Column of this field must be a `BelongsToMany` relation.');
    }
856987
protected function getForeignKeyName()
    {
        if (method_exists($this->relation, 'getQualifiedForeignPivotKeyName')) {
            $method = 'getQualifiedForeignPivotKeyName'; // Laravel 5.5
        } elseif (method_exists($this->relation, 'getQualifiedForeignKeyName')) {
            $method = 'getQualifiedForeignKeyName'; // Laravel 5.4
        } else {
            $method = 'getForeignKey'; // Laravel 5.3
        };

        return last(explode('.', $this->relation->$method()));
    }
1203565
public function getAutoIncrementPrimaryKey()
    {
        if (IdMethod::NO_ID_METHOD !== $this->getIdMethod()) {
            foreach ($this->getPrimaryKey() as $pk) {
                if ($pk->isAutoIncrement()) {
                    return $pk;
                }
            }
        }
    }