refactor relations
[m6w6/pq-gateway] / lib / pq / Gateway / Table / Attributes.php
index 39c55c948e00fbdfddb7058780f275c81c321411..0ba2d707b2df0e23ce87280a6cc344fa1a16324d 100644 (file)
@@ -17,7 +17,7 @@ const ATTRIBUTES_SQL = <<<SQL
        and   attnum   > 0
 SQL;
 
-class Attributes
+class Attributes implements \IteratorAggregate
 {
        /**
         * @var array
@@ -29,14 +29,14 @@ class Attributes
         */
        function __construct(Table $table) {
                $cache = $table->getMetadataCache();
-               if (!($this->columns = $cache->get("$table#attributes"))) {
+               if (!($this->columns = $cache->get("$table:attributes"))) {
                        $table->getQueryExecutor()->execute(
                                new \pq\Query\Writer(ATTRIBUTES_SQL, array($table->getName())), 
                                function($result) use($table, $cache) {
                                        foreach ($result->fetchAll(\pq\Result::FETCH_OBJECT) as $c) {
                                                $this->columns[$c->index] = $this->columns[$c->name] = $c;
                                        }
-                                       $cache->set("$table#attributes", $this->columns);
+                                       $cache->set("$table:attributes", $this->columns);
                                }
                        );
                }
@@ -69,4 +69,12 @@ class Attributes
                }
                return $this->columns[$c];
        }
+       
+       /**
+        * Implements \IteratorAggregate
+        * @return \ArrayIterator
+        */
+       function getIterator() {
+               return new \ArrayIterator($this->columns);
+       }
 }