private function processAllWith(&$data, $shouldReset = true)
{
if (count($this->_with) == 0) {
return;
}
foreach ($this->_with as $name => $opts) {
$relationType = strtolower($opts[0]);
$modelName = $opts[1];
if ($relationType == 'hasone') {
$obj = new $modelName();
$table = $obj->dbTable;
$primaryKey = $obj->primaryKey;
if (!isset($data[$table])) {
$data[$name] = $this->{$name};
continue;
}
if ($data[$table][$primaryKey] === null) {
$data[$name] = null;
} else {
if ($this->returnType == 'Object') {
$item = new $modelName($data[$table]);
$item->returnType = $this->returnType;
$item->isNew = false;
$data[$name] = $item;
} else {
$data[$name] = $data[$table];
}
}
unset($data[$table]);
} else {
$data[$name] = $this->{$name};
}
}
if ($shouldReset) {
$this->_with = array();
}
}