/** * Produces a Dataface_Record object representing the portion of this related record that is stored in a * particular table. * @param string $tablename The name of the table for which we wich to have a Dataface_Record object returned. * @since 0.6 */ function &toRecord($tablename = null) { if (isset($this->cache[__FUNCTION__][$tablename])) { return $this->cache[__FUNCTION__][$tablename]; } if (!isset($tablename)) { $tablename = $this->_relationship->getDomainTable(); } $table =& Dataface_Table::loadTable($tablename); $values = array(); $absVals = $this->getAbsoluteValues(); $fieldnames = $this->_relationship->fields(true); //foreach ( array_keys($absVals) as $key ){ foreach ($fieldnames as $key) { list($currTablename, $columnName) = explode('.', $key); if (($currTablename == $tablename or $table->hasField($columnName)) and array_key_exists($key, $absVals)) { $values[$columnName] = $absVals[$key]; } else { if (isset($this->_relationship->_schema['aliases'][$columnName])) { $values[$this->_relationship->_schema['aliases'][$columnName]] = $absVals[$key]; } } } $record = new Dataface_Record($tablename, $values); $record->secureDisplay = $this->secureDisplay; foreach (array_keys($values) as $key) { if ($this->isDirty($key)) { $record->setFlag($key); } } $this->cache[__FUNCTION__][$tablename] =& $record; return $record; }