1 # class pq\Gateway\Table\Relations implements Countable, IteratorAggregate
3 Retrieve any relations referenced by the table through foreign keys.
4 See pq\Gateway\Table::by() and pq\Gateway\Table::with().
8 The following query is executed by the current executor of the table to retrieve the table references:
11 case when att1.attname like '%\_'||att2.attname then
12 substring(att1.attname from '^.*(?=_'||att2.attname||'$)')
16 ,cl1.relname as "foreignTable"
17 ,att1.attname as "foreignColumn"
18 ,cl2.relname as "referencedTable"
19 ,att2.attname as "referencedColumn"
30 and co.conrelid = cl1.oid
31 and co.conkey[1] = att1.attnum and cl1.oid = att1.attrelid
32 and co.confrelid = cl2.oid
33 and co.confkey[1] = att2.attnum and cl2.oid = att2.attrelid
40 The result of this query is cached in the metadata cache under the following key, where $table is converted to a string by pq\Gateway\Table::__toString():
44 ## Foreign key access:
46 Relations can be accessed as virtual properties or through pq\Gateway\Table\Relations::getReference().
52 $relations = new Table\Relations(new Table("account_email"));
54 // $relations->reference->account
55 $account_rel = $relations->getReference("account");
56 $account_rel = $relations->account;
61 The relation name is the column name of the foreign key with the column name of the referenced column cut off the end.
65 * protected array $references
66 The table's foreign keys.