+
+ /**
+ * Get the child rows of a row by foreign key
+ * @param \pq\Gateway\Row $foreign
+ * @param string $name optional fkey name
+ * @param string $order
+ * @param int $limit
+ * @param int $offset
+ * @return mixed
+ */
+ function of(Row $foreign, $name = null, $order = null, $limit = 0, $offset = 0) {
+ // select * from $this where $this->$foreignColumn = $foreign->$referencedColumn
+
+ if (!isset($name)) {
+ $name = $this->getName();
+ }
+
+ if (!$foreign->getTable()->hasRelation($name, $this->getName())) {
+ return $this->onResult(null);
+ }
+ $rel = $foreign->getTable()->getRelations($name)->{$this->getName()};
+
+ return $this->find(
+ array($rel->foreignColumn . "=" => $foreign->{$rel->referencedColumn}),
+ $order, $limit, $offset
+ );
+ }
+
+ /**
+ * Get the parent rows of a row by foreign key
+ * @param \pq\Gateway\Row $me
+ * @param string $foreign
+ * @param string $order
+ * @param int $limit
+ * @param int $offset
+ * @return mixed
+ */
+ function by(Row $me, $foreign, $order = null, $limit = 0, $offset = 0) {
+ // select * from $foreign where $foreign->$referencedColumn = $me->$foreignColumn
+
+ if (!$this->hasRelation($foreign, $this->getName())) {
+ return $this->onResult(null);
+ }
+ $rel = $this->getRelations($foreign)->{$this->getName()};
+
+ return static::resolve($rel->referencedTable)->find(
+ array($rel->referencedColumn . "=" => $me->{$rel->foreignColumn}),
+ $order, $limit, $offset
+ );
+ }