Get a back reference key for an association on a table

"How would $table be referenced by another table under $name?"

Convention is "$table_id"

@param string $table
@param string $name
@return string
776494
function getBackReference( $table, $name ) {

        if ( isset( $this->backReferences[ $table ][ $name ] ) ) {

            return $this->backReferences[ $table ][ $name ];

        }

        return $table . '_id';

    }
531301
public function getTableDefinition($table)
    {
        foreach ($this->getTableDefinitions() as $definition) {
            if ($definition->getName() === $table) {
                return $definition;
            }
        }

        return null;
    }
5886
protected function findTableFromName($name)
    {
        foreach ($this->tables as $table) {
            if ($table->getName() === $name) {
                return $table;
            }
        }

        return null;
    }
97433
public function addPrimaryKey($name, $target, $table = null)
    {
        return $this->db->alterTable($this->getTable($table))
                        ->addConstraint($name)
                        ->primaryKey($target)
                        ->execute();
    }
1151224
public function getPrimaryKey($table)
	{
		$keys = $this->getTableKeys($table);
		$key  = false;

		if ($keys && count($keys) > 0)
		{
			foreach ($keys as $k)
			{
				if ($k->Key_name == 'PRIMARY')
				{
					$key = $k->Column_name;
				}
			}
		}

		return $key;
	}
550227
protected function resolveTableNames($table,$name)
	{
		$parts=explode('.',str_replace('`','',$name));
		if(isset($parts[1]))
		{
			$table->schemaName=$parts[0];
			$table->name=$parts[1];
			$table->rawName=$this->quoteTableName($table->schemaName).'.'.$this->quoteTableName($table->name);
		}
		else
		{
			$table->name=$parts[0];
			$table->rawName=$this->quoteTableName($table->name);
		}
	}
322734
public function getTableName($name)
    {
        $tableName = null;
        if (isset($this->app['schema.tables'][$name])) {
            /** @var BaseTable $table */
            $table = $this->app['schema.tables'][$name];
            $tableName = $table->getTableName();
        }

        return $tableName;
    }
579135
private function extractPkName($table)
    {
        if (is_null($this->pk)) {
            // This has been tested only in MySQL so far
            $row = $this->db->showKeys()
                            ->from($table)
                            ->whereEquals('Key_name', 'PRIMARY')
                            ->getStmt()
                            ->fetch();

            $this->pk = $row['Column_name'];
        }

        return $this->pk;
    }
572526
public function get_unique_primary($table): ?string
  {
    if ( ($keys = $this->get_keys($table)) &&
      isset($keys['keys']['PRIMARY']) &&
      (\count($keys['keys']['PRIMARY']['columns']) === 1) ){
      return $keys['keys']['PRIMARY']['columns'][0];
    }
    return null;
  }
351824
public function get_table( $table ) {
		if (
			! isset( $this->table_defines[ $table ] ) ||
			! empty( $this->table_defines[ $table ]['wordpress'] ) ||
			! empty( $this->table_defines[ $table ]['global'] )
		) {
			return $table;
		}

		return $this->get_table_prefix() . $table;
	}
691263
public function getTableKeys($table)
	{
		$this->connect();

		/** @var OracleQuery $query */
		$query = $this->getQuery(true);

		$fieldCasing = $this->getOption(\PDO::ATTR_CASE);

		$this->setOption(\PDO::ATTR_CASE, \PDO::CASE_UPPER);

		$table = strtoupper($table);
		$query->select('*');
		$query->from('ALL_CONSTRAINTS');
		$query->where('table_name = :tableName');

		$query->bind(':tableName', $table);

		$this->setQuery($query);
		$keys = $this->loadObjectList();

		$this->setOption(\PDO::ATTR_CASE, $fieldCasing);

		return $keys;
	}
1095254
final public function fetchTableDef(string $table) {
        $tableKey = strtolower($table);

        // First check the table cache.
        if (isset($this->tables[$tableKey])) {
            $tableDef = $this->tables[$tableKey];

            if (isset($tableDef['columns'], $tableDef['indexes'])) {
                return $tableDef;
            }
        } elseif ($this->tableNames !== null && !isset($this->tableNames[$tableKey])) {
            return null;
        }

        $tableDef = $this->fetchTableDefDb($table);
        if ($tableDef !== null) {
            $this->fixIndexes($tableDef['name'], $tableDef);
            $this->tables[$tableKey] = $tableDef;
        }

        return $tableDef;
    }
152561
protected function getForeignKey($name)
    {
        if (strpos($name, '\\')) {
            $name = basename(str_replace('\\', '/', $name));
        }

        return Db::parseName($name) . '_id';
    }
1220968
public function add(string $name, Table $table)
    {
        $this->tables[$name] = $table;

        return $this;
    }
1047023
function getReference($table, $ref = null) {
		if (isset($this->references[$table])) {
			if (!strlen($ref)) {
				return current($this->references[$table]);
			}
			if (isset($this->references[$table][$ref])) {
				return $this->references[$table][$ref];
			}
		}
	}
910181
public function getEvent(string $name, string $table = null): ?callable
    {
        return $this->connection->getEventHandler()->getEvent($name, $table);
    }
1131048
protected function _getForeignKey(Table $table, string $modelName) : string
    {
        foreach ($table->associations() as $association) {
            if ($modelName !== $association->className()) {
                continue;
            }

            $primaryKey = $association->getForeignKey();
            if (! is_string($primaryKey)) {
                throw new RuntimeException('Primary key must be a string');
            }

            return $primaryKey;
        }

        return '';
    }