/** * 建立关联,并且返回新建立的关联对象 * * @param array $defines * @param enum $type * * @return FLEA_Db_TableLink */ function createLink($defines, $type) { if (!is_array($defines)) { return; } if (!is_array(reset($defines))) { $defines = array($defines); } // 创建关联对象 foreach ($defines as $define) { if (!is_array($define)) { continue; } // 构造连接对象实例 $link =& FLEA_Db_TableLink::createLink($define, $type, $this); $this->links[strtoupper($link->name)] =& $link; } }
/** * 完全初始化关联对象 */ function init() { parent::init(); if ($this->joinTableClass) { $this->joinTDG =& FLEA::getSingleton($this->joinTableClass); $this->joinTable = $this->joinTDG->tableName; $joinSchema = $this->joinTDG->schema; } else { $joinSchema = $this->mainTDG->schema; } if (is_null($this->joinTable)) { $this->joinTable = $this->getMiddleTableName($this->mainTDG->tableName, $this->assocTableName); } if (is_null($this->foreignKey)) { $this->foreignKey = $this->mainTDG->primaryKey; } $this->joinTable = $this->dbo->dsn['prefix'] . $this->joinTable; $this->qjoinTable = $this->dbo->qtable($this->joinTable, $joinSchema); $this->qforeignKey = $this->dbo->qfield($this->foreignKey, $this->joinTable, $joinSchema); if (is_null($this->assocForeignKey)) { $this->assocForeignKey = $this->assocTDG->primaryKey; } $this->qassocForeignKey = $this->dbo->qfield($this->assocForeignKey, $this->joinTable, $this->mainTDG->schema); }