_left = &$left; $this->_middle = &$middle; $this->_right = &$right; } function &createQuery($id) { $left_key = $this->_middle->getForeignKey($this->_left->getName()); $middle_table = $this->_middle->getTable(); $middle_key = $this->_middle->getForeignKey($this->_right->getName()); $right_table = $this->_right->getTable(); $right_pk = $this->_right->getPrimaryKey(); $select = "r.*"; $from = "$middle_table as m, $right_table as r"; $where = "m.$left_key=? AND m.$middle_key=r.$right_pk"; $query = &new FAQuery($select, $from, $where); $query->bind(1, $id); return $query; } } // The left table has the foreign key class FALeftRelation extends FARelation { function FALeftRelation(&$left, &$right) { $this->_left = &$left; $this->_right = &$right; } function &createQuery($id) { $left_table = $this->_left->getTable(); $left_key = $this->_left->getForeignKey($this->_left->getName()); $left_pk = $this->_left->getPrimaryKey(); $right_table = $this->_right->getTable(); $right_pk = $this->_right->getPrimaryKey(); $select = "r.*"; $from = "$left_table as l, $right_table as r"; $where = "l.$left_key=r.$right_pk AND l.$left_pk=?"; $query = &new FAQuery($select, $from, $where); $query->bind(1, $id); return $query; } } // The right table has the foreign key class FAOneToManyRelation extends FARelation { function FAOneToManyRelation(&$left, &$right) { $this->_left = &$left; $this->_right = &$right; } function &createQuery($id) { $right_table = $this->_right->getTable(); $right_key = $this->_right->getForeignKey($this->_left->getName()); $select = "r.*"; $from = "$right_table as r"; $where = "r.$right_key=?"; $query = &new FAQuery($select, $from, $where); $query->bind($id); return $query; } } ?>