Browse Source

Fixes #8012: Fixed fetching multiple relations between two tables for pgsql

tags/2.0.4
Jan Waś 10 years ago committed by Alexander Makarov
parent
commit
ced423b601
  1. 1
      framework/CHANGELOG.md
  2. 18
      framework/db/pgsql/Schema.php

1
framework/CHANGELOG.md

@ -18,6 +18,7 @@ Yii Framework 2 Change Log
- Bug #7868: Fixed creating raw sql (for logging) by skipping object and resource params (nineinchnick)
- Bug #7868: Fixed Schema::getLastInsertID() by quoting sequence name (nineinchnick)
- Bug #7957: Removed extra `parseFloat()` call for the `compare` js validator (CthulhuDen)
- Bug #8012: Fixed fetching multiple relations between two tables for pgsql (nineinchnick)
- Bug #8014: Fixed setting incorrect form "action" property after submitting a form using a link with "data-method" and containing "action" among "data-params" (samdark)
- Enh #6895: Added `ignoreCategories` config option for message command to ignore categories specified (samdark)
- Enh #6975: Pressing arrows while focused in inputs of Active Form with `validateOnType` enabled no longer triggers validation (slinstj)

18
framework/db/pgsql/Schema.php

@ -225,12 +225,13 @@ SQL;
$sql = <<<SQL
select
ct.conname as constraint_name,
a.attname as column_name,
fc.relname as foreign_table_name,
fns.nspname as foreign_table_schema,
fa.attname as foreign_column_name
from
(SELECT ct.conrelid, ct.confrelid, ct.conkey, ct.contype, ct.confkey, generate_subscripts(ct.conkey, 1) AS s
(SELECT ct.conname, ct.conrelid, ct.confrelid, ct.conkey, ct.contype, ct.confkey, generate_subscripts(ct.conkey, 1) AS s
FROM pg_constraint ct
) AS ct
inner join pg_class c on c.oid=ct.conrelid
@ -254,14 +255,17 @@ SQL;
} else {
$foreignTable = $constraint['foreign_table_name'];
}
$constraints[$foreignTable][$constraint['column_name']] = $constraint['foreign_column_name'];
$name = $constraint['constraint_name'];
if (!isset($constraints[$name])) {
$constraints[$name] = [
'tableName' => $foreignTable,
'columns' => [],
];
}
foreach ($constraints as $foreignTable => $columns) {
$citem = [$foreignTable];
foreach ($columns as $column => $foreignColumn) {
$citem[$column] = $foreignColumn;
$constraints[$name]['columns'][$constraint['column_name']] = $constraint['foreign_column_name'];
}
$table->foreignKeys[] = $citem;
foreach ($constraints as $constraint) {
$table->foreignKeys[] = array_merge([$constraint['tableName']], $constraint['columns']);
}
}

Loading…
Cancel
Save