/** * ar->foreignName will contain the name of the tables associated with this table because * this table's rows may also be referenced by those tables using thistable_id or the provided * foreign keys (this index name is stored in ar->foreignKey) * * this-table.other-table_id = other-table.id */ function belongsTo($foreignRef, $foreignKey = false) { global $inflector; $ar = new ADODB_Active_Record($this->_pluralize($foreignRef)); $ar->foreignName = $foreignRef; $ar->UpdateActiveTable(); $ar->foreignKey = $foreignKey ? $foreignKey : $ar->foreignName . self::$_foreignSuffix; $table =& $this->TableInfo(); if (!isset($table->_belongsTo[$foreignRef])) { $table->_belongsTo[$foreignRef] = $ar; $table->updateColsCount(); } $this->{$foreignRef} = $table->_belongsTo[$foreignRef]; }
function belongsTo($foreignRef, $foreignKey = false, $parentKey = '') { global $inflector; $ar = new ADODB_Active_Record($this->_pluralize($foreignRef)); $ar->foreignName = $foreignRef; $ar->parentKey = $parentKey; $ar->UpdateActiveTable(); $ar->foreignKey = $foreignKey ? $foreignKey : $foreignRef . ADODB_Active_Record::$_foreignSuffix; $table =& $this->TableInfo(); $table->_belongsTo[$foreignRef] = $ar; # $this->$foreignRef = $this->_belongsTo[$foreignRef]; }