add identity and lock
[m6w6/pq-gateway] / lib / pq / Gateway / Table / Relations.php
index 128dca7ebb53aae950c8059bce4add4a1cd73859..ab74d4060b23bdd49b7d795aa8b29101b2486cb7 100644 (file)
@@ -30,17 +30,26 @@ order by
        ,att1.attnum
 SQL;
 
+/**
+ * A foreighn key implementation
+ */
 class Relations
 {
-       public $references;
+       /**
+        * @var array
+        */
+       protected $references;
        
        function __construct(Table $table) {
                $cache = $table->getMetadataCache();
-               if (!($this->references = $cache->get("$table:references"))) {
-                       $this->references = $table->getConnection()
-                               ->execParams(RELATION_SQL, array($table->getName()))
-                               ->map(array(0,1), array(2,3,4), \pq\Result::FETCH_OBJECT);
-                       $cache->set("$table:references", $this->references);
+               if (!($this->references = $cache->get("$table#relations"))) {
+                       $table->getQueryExecutor()->execute(
+                               new \pq\Query\Writer(RELATION_SQL, array($table->getName())),
+                               function($result) use($table, $cache) {
+                                       $this->references = $result->map(array(0,1), array(2,3,4), \pq\Result::FETCH_OBJECT);
+                                       $cache->set("$table#relations", $this->references);
+                               }
+                       );
                }
        }