+ * @param string $lock
+ * @return mixed
+ */
+ function find(array $where = null, $order = null, $limit = 0, $offset = 0, $lock = null) {
+ $query = $this->getQueryWriter()->reset();
+ $query->write("SELECT * FROM", $this->conn->quoteName($this->name));
+ if ($where) {
+ $query->write("WHERE")->criteria($where);
+ }
+ if ($order) {
+ $query->write("ORDER BY", $order);
+ }
+ if ($limit) {
+ $query->write("LIMIT", $limit);
+ }
+ if ($offset) {
+ $query->write("OFFSET", $offset);
+ }
+ if ($lock) {
+ $query->write("FOR", $lock);
+ }
+ return $this->execute($query);
+ }
+
+ /**
+ * Get the child rows of a row by foreign key
+ * @param \pq\Gateway\Row $foreign
+ * @param string $ref optional fkey name
+ * @param string $order
+ * @param int $limit
+ * @param int $offset
+ * @return mixed
+ */
+ function of(Row $foreign, $ref = null, $order = null, $limit = 0, $offset = 0) {
+ // select * from $this where $this->$foreignColumn = $foreign->$referencedColumn
+
+ if (!($rel = $this->getRelation($foreign->getTable()->getName(), $ref))) {
+ return $this->onResult(null);
+ }
+
+ $where = array();
+ foreach ($rel as $key => $ref) {
+ $where["$key="] = $foreign->$ref;
+ }
+
+ return $this->find($where, $order, $limit, $offset);
+ }
+
+ /**
+ * Get the parent rows of a row by foreign key
+ * @param \pq\Gateway\Row $foreign
+ * @param string $ref
+ * @return mixed
+ */
+ function by(Row $foreign, $ref = null) {
+ // select * from $this where $this->$referencedColumn = $me->$foreignColumn
+
+ if (!($rel = $foreign->getTable()->getRelation($this->getName(), $ref))) {
+ return $this->onResult(null);
+ }
+
+ $where = array();
+ foreach ($rel as $key => $ref) {
+ $where["$ref="] = $foreign->$key;
+ }
+ return $this->find($where);
+ }
+
+ /**
+ * Get rows dependent on other rows by foreign keys
+ * @param array $relations
+ * @param array $where
+ * @param string $order
+ * @param int $limit
+ * @param int $offset
+ * @return mixed