3 namespace pq\Gateway\Table
;
7 const RELATION_SQL
= <<<SQL
9 substring(att1.attname from '^.*(?=_'||att2.attname||'$)') as "id"
10 ,cl1.relname as "foreignTable"
11 ,att1.attname as "foreignColumn"
12 ,cl2.relname as "referencedTable"
13 ,att2.attname as "referencedColumn"
24 and co.conrelid = cl1.oid
25 and co.conkey[1] = att1.attnum and cl1.oid = att1.attrelid
26 and co.confrelid = cl2.oid
27 and co.confkey[1] = att2.attnum and cl2.oid = att2.attrelid
37 function __construct(Table
$table) {
38 $cache = $table->getMetadataCache();
39 if (!($this->references
= $cache->get("$table:references"))) {
40 $this->references
= $table->getConnection()
41 ->execParams(RELATION_SQL
, array($table->getName()))
42 ->map(array(0,1), array(2,3,4), \pq\Result
::FETCH_OBJECT
);
43 $cache->set("$table:references", $this->references
);
47 function __isset($r) {
48 return isset($this->references
->$r);
52 return $this->references
->$r;
55 function __set($r, $v) {
56 $this->references
->$r = $v;
60 unset($this->references
->$r);