+ /**
+ * Get foreign key relations
+ * @param string $to fkey
+ * @return \pq\Gateway\Table\Relations|stdClass
+ */
+ function getRelations($to = null) {
+ if (!isset($this->relations)) {
+ $this->relations = new Table\Relations($this);
+ }
+ if (isset($to)) {
+ if (!isset($this->relations->$to)) {
+ return null;
+ }
+ return $this->relations->$to;
+ }
+ return $this->relations;
+ }
+
+ /**
+ * Check whether a certain relation exists
+ * @param string $name
+ * @param string $table
+ * @return bool
+ */
+ function hasRelation($name, $table = null) {
+ if (!($rel = $this->getRelations($name))) {
+ return false;
+ }
+ if (!isset($table)) {
+ return true;
+ }
+ return isset($rel->$table);
+ }
+