632711f11cdf0e85c0196e55e59c0f119afa07ce
[mdref/mdref-pq-gateway] / pq-gateway / pq / Gateway / Table / getRelation.md
1 # pq\Gateway\Table\Reference pq\Gateway\Table::getRelation(string $table[, string $ref = NULL])
2
3 Retrieve the foreign key of the table to another table.
4 See pq\Gateway\Table\Relations::getReference().
5
6 ## Params:
7
8 * string $table
9 The table name referenced by a foreign key of the table.
10 * Optional string $ref = NULL
11 A specific relation id if there are more foreign keys to the same table.
12
13 ## Returns:
14
15 * pq\Gateway\Table\Reference, the foreign key.
16 * NULL, if the tables are not related.
17
18 ## Example:
19
20 <?php
21
22 use pq\Gateway\Table;
23
24 $email = new Table("account_email");
25 $ref = $email->getRelation("account");
26
27 var_dump($ref);
28
29 ?>
30
31 Yields:
32
33 object(pq\Gateway\Table\Reference)#12 (5) {
34 ["name"]=>
35 string(7) "account"
36 ["foreignTable"]=>
37 string(13) "account_email"
38 ["foreignColumns"]=>
39 array(1) {
40 [0]=>
41 string(10) "account_id"
42 }
43 ["referencedTable"]=>
44 string(7) "account"
45 ["referencedColumns"]=>
46 array(1) {
47 [0]=>
48 string(2) "id"
49 }
50 }
51
52