Gets the foreign key field name

@return string
505747
public function getForeignKey()
    {
        if (is_null($this->foreignKey)) {
            $name = $this->getEntityDescriptor()->getTableName();
            $this->foreignKey = "{$this->normalizeFieldName($name)}_id";
        }
        return $this->foreignKey;
    }
1060479
protected function getMethodCallsForForeignKeys()
    {
        $methods = [];

        if ($keys = $this->getForeignKeys()) {
            /** @var ForeignKey $key */
            foreach ($keys as $key) {
                $relatedTable = $key->getRelatedTable();
                $relatedModel = '\\' . $this->getAppNamespace() . $relatedTable->getModelName() . '::class';

                if ($key->isSource()) {
                    $methodName = lcfirst($key->isForMany() ? $relatedTable->getName() : $relatedTable->getModelName());

                    $methodReturnSuffix = 'has' . ($key->isForMany() ? 'Many' : 'One');
                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel});";
                } // if
                elseif ($key->isForPivotTable()) {
                    $methodName = lcfirst($key->isForMany() && $key->isForPivotTable()
                        ? $relatedTable->getName()
                        : $relatedTable->getModelName());

                    $methodReturnSuffix = 'belongsToMany';

                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel});";
                } // elseif
                else {
                    $methodName = lcfirst($key->isForMany() && $key->isForPivotTable()
                        ? $relatedTable->getName()
                        : $relatedTable->getModelName());

                    $methodReturnSuffix = 'belongsTo';

                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel}, '{$key->foreign}');";
                } // else

                $methodName = preg_replace_callback(
                    '/(_[a-z])/',
                    function ($matches) {
                        return strtoupper(substr($matches[0], 1));
                    },
                    $methodName
                );

                $method = "\t/**\n\t * Getter for {$relatedTable->getName()}.\n\t " .
                    "* @return \\Illuminate\\Database\\Eloquent\\Relations\\" .
                    ucfirst($methodReturnSuffix) . " \n\t */\n\t" .
                    "public function {$methodName}()\n\t{\n\t\t{$methodContent}\n\t}";

                $methods[] = $method;
            } // foreach
        } // if

        return array_unique($methods);
    }
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';
        });
    }
1152509
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();
            $fullKeyArray = explode('.', $fullKey);

            return $this->otherKey = end($fullKeyArray);
        }

        throw new \Exception('Column of this field must be a `BelongsToMany` relation.');
    }
911373
function getBelongsToName(fkc) {
    var as          = fkc.foreignKey(0).name(),                                             // company_id
        tableName   = fkc.table().name(),
        camelCase   = getSpecificConfig(tableName, 'generate.relationAccessorCamelCase'),
        prefix      = getSpecificConfig(tableName, 'generate.prefixForBelongsTo');          // related

    if (as.match(/_id$/i)) {
        as = as.replace(/_id$/i, '');                                                       // company_id -> company
    } else {
        as = prefix + '_' + as;                                                             // company -> related_company
    }
    if (camelCase) {
        as = inflection.camelize(inflection.underscore(as), true);
    }
    return inflection.singularize(as);
}
1331833
protected function getRelatedKeyName()
    {
        if (method_exists($this->relation, 'getQualifiedRelatedPivotKeyName')) {
            $method = 'getQualifiedRelatedPivotKeyName'; // Laravel 5.5
        } elseif (method_exists($this->relation, 'getQualifiedRelatedKeyName')) {
            $method = 'getQualifiedRelatedKeyName'; // Laravel 5.4
        } else {
            $method = 'getOtherKey'; // Laravel 5.3
        };

        return last(explode('.', $this->relation->$method()));
    }
931316
protected function getNameFromParent()
    {
        $base = $this->gridField;
        $name = array();

        do {
            array_unshift($name, $base->getName());
            $base = $base->getForm();
        } while ($base && !($base instanceof Form));

        return implode('.', $name);
    }
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;
    }
468495
public function getDbName()
    {
        // Special handler for "NULL" relations
        if ($this->name === "NULL") {
            return $this->name;
        }

        // Ensure that we're dealing with a DataObject.
        if (!is_subclass_of($this->model, DataObject::class)) {
            throw new InvalidArgumentException(
                "Model supplied to " . static::class . " should be an instance of DataObject."
            );
        }
        $tablePrefix = DataQuery::applyRelationPrefix($this->relation);
        $schema = DataObject::getSchema();

        if ($this->aggregate) {
            $column = $this->aggregate['column'];
            $function = $this->aggregate['function'];

            $table = $column ?
                $schema->tableForField($this->model, $column) :
                $schema->baseDataTable($this->model);

            if (!$table) {
                throw new InvalidArgumentException(sprintf(
                    'Invalid column %s for aggregate function %s on %s',
                    $column,
                    $function,
                    $this->model
                ));
            }
            return sprintf(
                '%s("%s%s".%s)',
                $function,
                $tablePrefix,
                $table,
                $column ? "\"$column\"" : '"ID"'
            );
        }


        // Check if this column is a table on the current model
        $table = $schema->tableForField($this->model, $this->name);
        if ($table) {
            return $schema->sqlColumnForField($this->model, $this->name, $tablePrefix);
        }

        // fallback to the provided name in the event of a joined column
        // name (as the candidate class doesn't check joined records)
        $parts = explode('.', $this->fullName);
        return '"' . implode('"."', $parts) . '"';
    }
469639
protected function getKeyName()
    {
        if (is_null($this->form)) {
            return;
        }

        return $this->form->model()->{$this->relationName}()->getRelated()->getKeyName();
    }
451802
private function getDocumentFieldName()
    {
        $parts = explode('.', $this->node->getField());
        if ($this->nodeFieldNameHasLanguage()) {
            array_pop($parts);
        }
        return implode('.', $parts);
    }
1260090
protected function getRelationName()
    {
        $relation = array_get($this->actionData->options(), 'relation');

        if ($relation) {
            return $relation;
        }

        /** @var ModelInformationRepositoryInterface $infoRepository */
        $infoRepository = app(ModelInformationRepositoryInterface::class);

        $info = $infoRepository->getByModelClass($this->otherModelClass);

        if ( ! $info || empty($info->list->parents) || count($info->list->parents) !== 1) {
            return false;
        }

        return head($info->list->parents)->relation;
    }
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);
    }
817636
public function getPrimaryKeyName()
    {
        if (!isset($this->primaryKeyName)) {
            // lazy load
            $memory = $this->getDI()->get('memory');
            $attributes = $memory->getPrimaryKeyAttributes($this);
            $attributeKey = $attributes[0];

            // adjust for colMaps if any are provided
            $colMap = $memory->getColumnMap($this);
            if (is_null($colMap)) {
                $this->primaryKeyName = $attributeKey;
            } else {
                $this->primaryKeyName = $colMap[$attributeKey];
            }
        }
        return $this->primaryKeyName;
    }
351152
public function getPrimaryKeyForForeignModel()
    {
        $model = $this->getForeignModelInstance();

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

        return $this->getKeyNameFromResource() ?: 'id';
    }
529617
public function getExpr()
    {
        $q = $this->owner->_dsql();

        return $q->bt($this->relation ? $this->relation->short_name : $q->main_table).'.'.
            $q->bt($this->actual_field ?: $this->short_name);
    }
178674
public function getFieldNames()
    {
        $fieldNames = $this->_aFieldNames;

        if (!$this->isAdmin() && $this->_blUseLazyLoading) {
            $fieldNames = $this->_getNonCachedFieldNames(true);
        }

        return array_keys($fieldNames);
    }