public function generateFK($tableSchema = null)
{
if (is_null($tableSchema)) {
$tableSchema = $this->getTableSchema();
}
$fk = [];
if (isset($this->relations[$tableSchema->fullName])) {
foreach ($this->relations[$tableSchema->fullName] as $name => $relations) {
foreach ($tableSchema->foreignKeys as $value) {
if (isset($relations[self::REL_FOREIGN_KEY]) && $relations[self::REL_TABLE] == $value[self::FK_TABLE_NAME]) {
if ($tableSchema->fullName == $value[self::FK_TABLE_NAME] && $relations[self::REL_IS_MULTIPLE]) {
// In case of self-referenced tables (credit to : github.com/iurijacob)
} else {
$fk[$relations[5]] = $relations;
$fk[$relations[5]][] = $name;
}
}
}
}
}
return $fk;
}