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.confrelid = cl2.oid
25 and co.conrelid = cl1.oid
26 and co.confkey[1] = att2.attnum and cl2.oid = att2.attrelid
27 and co.conkey[1] = att1.attnum and cl1.oid = att1.attrelid
37 function __construct(Table
$table) {
39 $this->references
= $table->getConnection()
40 ->execParams(RELATION_SQL
, array($table->getName()))
41 ->map(array(0,1), array(2,3,4), \pq\Result
::FETCH_OBJECT
);
44 function __isset($r) {
45 return isset($this->references
->$r);
49 return $this->references
->$r;
52 function __set($r, $v) {
53 $this->references
->$r = $v;
57 unset($this->references
->$r);