From: Michael Wallner Date: Fri, 3 May 2013 12:32:40 +0000 (+0200) Subject: ensure accessing a cell on ref update X-Git-Tag: v1.0.0~1 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=commitdiff_plain;h=b39e14404cfeac177d41b152690b6adbb2b1e4bf ensure accessing a cell on ref update --- diff --git a/lib/pq/Gateway/Row.php b/lib/pq/Gateway/Row.php index 6d9c19e..cda8d4a 100644 --- a/lib/pq/Gateway/Row.php +++ b/lib/pq/Gateway/Row.php @@ -184,6 +184,18 @@ class Row implements \JsonSerializable return $changes; } + /** + * Cell accessor + * @param string $p column name + * @return \pq\Gateway\Cell + */ + protected function cell($p) { + if (!isset($this->cell[$p])) { + $this->cell[$p] = new Cell($this, $p, isset($this->data[$p]) ? $this->data[$p] : null); + } + return $this->cell[$p]; + } + /** * Get a cell or parent rows * @param string $p @@ -193,10 +205,7 @@ class Row implements \JsonSerializable if ($this->table->hasRelation($p)) { return $this->table->by($this, $p); } - if (!isset($this->cell[$p])) { - $this->cell[$p] = new Cell($this, $p, isset($this->data[$p]) ? $this->data[$p] : null); - } - return $this->cell[$p]; + return $this->cell($p); } /** @@ -205,7 +214,7 @@ class Row implements \JsonSerializable * @param mixed $v */ function __set($p, $v) { - $this->__get($p)->set($v); + $this->cell($p)->set($v); } /** diff --git a/tests/lib/pq/Gateway/CellTest.php b/tests/lib/pq/Gateway/CellTest.php index fc08ba6..9235a39 100644 --- a/tests/lib/pq/Gateway/CellTest.php +++ b/tests/lib/pq/Gateway/CellTest.php @@ -50,4 +50,15 @@ class CellTest extends \PHPUnit_Framework_TestCase { $this->assertEquals("$key + 123 || 'foobar' - now()", (string) $row->$key); } } + + public function testRef() { + $rows = $this->table->find(null, "id desc", 2); + $reft = new Table("reftest"); + $refs = new Rowset($reft); + $refs->append($rows->seek(0)->current()->reftest()->current()); + $refs->append($rows->seek(1)->current()->reftest()->current()); + $refs->seek(0)->current()->test = $rows->seek(1)->current(); + $refs->seek(1)->current()->test = $rows->seek(0)->current(); + $refs->update(); + } }