public static function getRelations(DB\Table $table) { //using namespace for the table identifier as there might be same name DBs on different servers $namespace = $table->getDatabase()->getNamespace(); $relation_cache = self::_getRelationCache($table); $relations = array(); //may not be any constraints if ($relation_cache !== null) { foreach ($relation_cache as $cached_row) { //--- check both ends of the relation can be built. $local_db = DB::getByConfig(array('database' => $cached_row['table_catalog'], 'schema' => $cached_row['table_schema'])); if ($local_db === null) { Log::write('pgsql_driver', sprintf('Database [%s] is not referenced in the configuration - skipping building relations.', $cached_row['table_catalog']), Log::WARNING); continue; } $local_column = $local_db->getColumn($cached_row['table_name'], $cached_row['column_name']); //skip if there's no referenced schema. This is because primary keys will be in the relation cache (no ref schema) if ($cached_row['referenced_table_schema'] === null) { continue; } $referenced_db = DB::getByConfig(array('database' => $cached_row['referenced_table_catalog'], 'schema' => $cached_row['referenced_table_schema'])); if ($referenced_db === null) { Log::write('pgsql_driver', sprintf('Database [%s] is not referenced in the configuration - skipping building relations.', $cached_row['referenced_table_schema']), Log::WARNING); continue; } $referenced_column = $referenced_db->getColumn($cached_row['referenced_table_name'], $cached_row['referenced_column_name']); //----- $relation = DB\Relation::create($local_column, $referenced_column, $cached_row['constraint_name'], isset($cached_row['reverse'])); if ($relation !== null) { $relations[$relation->getIdentifyingName()] = $relation; } else { Log::write('mysql_driver', sprintf('[%s.%s.%s] has duplicate relations.', $cached_row['table_schema'], $cached_row['table_name'], $cached_row['column_name']), Log::WARNING); } } } return $relations; }