/** Polymorphism support: $peanut has been initialized from data, but
* some field values where not in the data. Probably the query the data
* was retrieved with, was created by a superclass' classDescriptor.
* run another query to retrieve the missing data and initialize
* the peanut from it.
* PRECONDITION: $delegator not null
* @param PntDbObject The peanut that is being retrieved
* @param integer $id The id of the object
* @param Array $missingFieldsMap With names of missing fields as keys and columnNames as values
* @param PntClassDescriptor $delegator The classDescriptor that issued the original query that resulted in delegation and missing fields
* @throws PntError
*/
function ($peanut, $id, &$missingFieldsMap, $delegator) {
//collect maps for missing tables and fields
$delegatorTableMap = $delegator->();
$ownTableMap = $this->();
$missingTableMap = array();
$fieldMapPrefixed = array();
forEach($missingFieldsMap as $field => $columnName) {
$prop = $this->($field);
$tableName = $prop->();
if (!isSet($delegatorTableMap[$tableName]) ) {
$missingTableMap[$tableName] = $ownTableMap[$tableName];
$fieldMapPrefixed[$field] = $tableName. ".". $columnName;
}
}
if (count($fieldMapPrefixed) == 0) return; //assume some of the fields that are normally retrieved by the delegator where left out deliberately
//there still are fields to retrieve, build query
$qh = $this->($this->(), $missingTableMap, $fieldMapPrefixed);
$qh->(key($missingTableMap).'.id', $id);
$qh->();
if ($qh->())
throw new PntReflectionError($qh->(), $qh->());
$row = $qh->();
$qh->();
if (!$row)
throw new PntReflectionError($this. "no rows when loading missing fields of: ". $peanut->());
$peanut->($peanut->($row, $missingFieldsMap));
}
|