public function setMapper($mapper)
{
if ($mapper === $this->mapper) {
return $this;
}
$this->mapper = $mapper;
// Fetch all non-lazy-loaded fields for the mapper.
$this->setFields($mapper->fields, $mapper->table . '.');
// Add all non-lazy relationships.
foreach ($mapper->relationships as $relationship => $rel) {
if (isset($rel['mapper'])) {
// @TODO - should be getting this instance from somewhere
// else external, and not passing the adapter along
// automatically.
$m = new $rel['mapper']($this->mapper->adapter);
} else {
$m = $this->mapper->tableToMapper($relationship);
if (is_null($m)) {
throw new Horde_Rdo_Exception('Unable to find a Mapper class for eager-loading relationship ' . $relationship);
}
}
// Add the fields for this relationship to the query.
$m->tableAlias = $this->_alias($m->table);
$this->addFields($m->fields, $m->tableAlias . '.@');
$args = array('mapper' => $m, 'type' => $rel['type']);
switch ($rel['type']) {
case Horde_Rdo::ONE_TO_ONE:
case Horde_Rdo::MANY_TO_ONE:
if (isset($rel['query'])) {
$args['query'] = $this->_fillJoinPlaceholders($m, $mapper, $rel['query']);
} else {
$args['query'] = array($mapper->table . '.' . $rel['foreignKey'] => new Horde_Rdo_Query_Literal($m->table . '.' . $m->tableDefinition->getPrimaryKey()));
}
if (isset($rel['join_type'])) {
$args['join_type'] = $rel['join_type'];
}
$this->addRelationship($relationship, $args);
break;
case Horde_Rdo::ONE_TO_MANY:
case Horde_Rdo::MANY_TO_MANY:
//@TODO
}
}
return $this;
}