You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: PostgreSQL describeReferences() gives the database name as the referenced schema #17816
Describe the bug
The query of Phalcon\Db\Dialect\Postgresql::describeReferences() gives current_database() AS REFERENCED_TABLE_SCHEMA. That is the name of the database, not the schema of the referenced table. So Reference::getReferencedSchema() is wrong for each foreign key on PostgreSQL. A key to a table in another schema cannot be followed.
To Reproduce
PostgreSQL, a database shop:
CREATESCHEMAbilling;
CREATETABLEpublic.customers (id intPRIMARY KEY);
CREATETABLEbilling.invoices (
id intPRIMARY KEY,
customer_id intREFERENCESpublic.customers (id)
);
CREATETABLEbilling.lines (
id intPRIMARY KEY,
invoice_id intREFERENCESbilling.invoices (id)
);
The query already joins pg_class AS fc ON fc.oid = con.confrelid (the referenced table) since #17680.
Details
Phalcon version: 5.0.x (927c773be7): phalcon/Db/Dialect/Postgresql.zep, describeReferences() (line 419; the column on line 436).
phalcon/phalcon v6.0.x (aeca48611) has the same query: src/Db/Dialect/Postgresql.php, describeReferences() (line 496; the column on line 515).
Tests: tests/database/Db/Dialect/DescribeReferencesTest.php (the SQL text) and tests/database/Db/Adapter/Pdo/DescribeReferencesPostgresqlTest.php.
Additional context
Found in phalcon/crest#86 (a schema for each table): crest make:model cannot write a relation for a foreign key to a table in another schema, because the referenced schema is wrong.
Activity
niden commentedon Nov 27, 2026
Resolved in #17820
[phalcon#17816] - giving the schema of the referenced table in Postgr…
[phalcon#17816] - updating changelog and ext