1 # \pq\Gateway\Table\Relations|stdClass pq\Gateway\Table::getRelations([string $to = NULL])
3 Get the relations (by foreign key) of this table.
4 See pq\Gateway\Table::hasRelation().
7 The relation name is the column name of the foreign key with the column name of the referenced column cut off the end.
11 * Optional string $to = NULL
12 The table name of which to get the relation to.
16 * stdClass, if $to is given and a relation exists.
17 * NULL, if $to is given and a relation does not exist.
18 * pq\Gateway\Table\Relations, all relations if $to is omitted.
26 $conn = new pq\Connection;
28 drop table if exists reftable cascade;
29 -- drop table if exists account cascade;
30 -- drop table if exists account_email cascade;
32 -- create table account (
33 -- id uuid default uuid_generate_v4() primary key,
38 -- create table account_email (
39 -- account_id uuid not null references account(id) on delete cascade,
40 -- email varchar(255) not null unique,
41 -- primary key (account_id, email)
44 create table reftable (
45 id serial primary key,
46 my_account integer references account(id),
47 account_id integer references account(id),
48 second_account_id integer references account(id),
49 email integer references account_email(email)
53 $fgn_table = new Table("reftable");
54 var_dump($fgn_table->getRelations());
60 object(pq\Gateway\Table\Relations)#10 (1) {
61 ["references":protected]=>
62 object(stdClass)#17 (4) {
64 object(stdClass)#18 (1) {
66 object(stdClass)#19 (4) {
70 string(10) "my_account"
73 ["referencedColumn"]=>
78 object(stdClass)#20 (1) {
80 object(stdClass)#21 (4) {
84 string(10) "account_id"
87 ["referencedColumn"]=>
92 object(stdClass)#22 (1) {
94 object(stdClass)#23 (4) {
98 string(17) "second_account_id"
101 ["referencedColumn"]=>
106 object(stdClass)#24 (1) {
108 object(stdClass)#25 (4) {
113 ["referencedTable"]=>
114 string(13) "account_email"
115 ["referencedColumn"]=>