protected function addInverseRelations($relations)
{
$relationNames = [];
foreach ($this->getSchemaNames() as $schemaName) {
foreach ($this->getDbConnection()->getSchema()->getTableSchemas($schemaName) as $table) {
$className = $this->generateClassName($table->fullName);
foreach ($table->foreignKeys as $refs) {
$refTable = $refs[0];
$refTableSchema = $this->getDbConnection()->getTableSchema($refTable);
unset($refs[0]);
$fks = array_keys($refs);
$leftRelationName = $this->generateRelationName($relationNames, $table, $fks[0], false);
$relationNames[$table->fullName][$leftRelationName] = true;
$hasMany = $this->isHasManyRelation($table, $fks);
$rightRelationName = $this->generateRelationName($relationNames, $refTableSchema, $className, $hasMany);
$relationNames[$refTableSchema->fullName][$rightRelationName] = true;
$relations[$table->fullName][$leftRelationName][0] = rtrim($relations[$table->fullName][$leftRelationName][0], ';') . "->inverseOf('" . lcfirst($rightRelationName) . "');";
$relations[$refTableSchema->fullName][$rightRelationName][0] = rtrim($relations[$refTableSchema->fullName][$rightRelationName][0], ';') . "->inverseOf('" . lcfirst($leftRelationName) . "');";
}
}
}
return $relations;
}