mdref.json config
[mdref/mdref-pq-gateway] / pq-gateway / pq / Gateway / Table / Relations / getReference.md
1 # pq\Gateway\Table\Reference pq\Gateway\Table\Relations::getReference(string $table[, string $ref = NULL])
2
3 Retrieve the foreign key of the table to another table.
4 See pq\Gateway\Table::getRelation().
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 $relation = new Table\Relations($email);
26 $account = $relation->getReference("account");
27
28 var_dump($account);
29
30 ?>
31
32 Yields:
33
34 object(pq\Gateway\Table\Reference)#12 (5) {
35 ["name"]=>
36 string(7) "account"
37 ["foreignTable"]=>
38 string(13) "account_email"
39 ["foreignColumns"]=>
40 array(1) {
41 [0]=>
42 string(10) "account_id"
43 }
44 ["referencedTable"]=>
45 string(7) "account"
46 ["referencedColumns"]=>
47 array(1) {
48 [0]=>
49 string(2) "id"
50 }
51 }
52
53