X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FGateway%2FRow.php;h=bfda71b0575cfe73aa43d3f08051a2bed79c11d5;hp=78ec4c4e9c2d38e6ef82c118a07c3bf19eb6772f;hb=ccdcd2977c8bdc7c74b89b2fb7c2ea46479692b8;hpb=80c4d645e1650304b1dbcae85dbf17a6593896e4 diff --git a/lib/pq/Gateway/Row.php b/lib/pq/Gateway/Row.php index 78ec4c4..bfda71b 100644 --- a/lib/pq/Gateway/Row.php +++ b/lib/pq/Gateway/Row.php @@ -197,14 +197,11 @@ class Row implements \JsonSerializable } /** - * Get a cell or parent rows + * Get a cell * @param string $p - * @return \pq\Gateway\Cell|\pq\Gateway\Rowset + * @return \pq\Gateway\Cell */ function __get($p) { - if ($this->table->hasRelation($p)) { - return $this->table->by($this, $p); - } return $this->cell($p); } @@ -235,17 +232,40 @@ class Row implements \JsonSerializable return isset($this->data[$p]) || isset($this->cell[$p]); } + /** + * Get the parent row + * @see \pq\Gateway\Table::by() + * @param mixed $foreign table (name) + * @param string $ref + * @return \pq\Gateway\Rowset + */ + function ofWhich($foreign, $ref = null) { + if (!($foreign instanceof Table)) { + $foreign = forward_static_call( + [get_class($this->getTable()), "resolve"], + $foreign + ); + } + return $foreign->by($this, $ref); + } + /** * Get child rows of this row by foreign key * @see \pq\Gateway\Table::of() - * @param string $foreign - * @param array $args [order, limit, offset] + * @param mixed $foreign table (name) + * @param string $order + * @param int $limit + * @param int $offset * @return \pq\Gateway\Rowset */ - function __call($foreign, array $args) { - array_unshift($args, $this); - $table = forward_static_call(array(get_class($this->getTable()), "resolve"), $foreign); - return call_user_func_array(array($table, "of"), $args); + function allOf($foreign, $ref = null, $order = null, $limit = 0, $offset = 0) { + if (!($foreign instanceof Table)) { + $foreign = forward_static_call( + [get_class($this->getTable()), "resolve"], + $foreign + ); + } + return $foreign->of($this, $ref, $order, $limit, $offset); } /**