protected function addAutoJoin(Zend_Db_Table_Select $select)
{
$tables = array();
$columns = array();
$references = $this->getDefaultAdapter()->getReferences(null, $this->_name);
if ($references) {
foreach ($references as $key => $reference) {
$tableName = $reference['table'];
$table = new La_Db_Table($tableName);
$columnName = $table->getNameForOptionField();
$comments = $this->getComments();
$column = $reference['columns'];
$columnAlias = $comments[$column];
$tableAlias = $tableName . $key;
$columns[$columnAlias] = $tableAlias . '.' . $columnName;
$tables[$tableName] = $tableName;
$joinTable = array($tableAlias => $tableName);
$condition = sprintf('`%s`.`id` = `%s`.`%s`', $tableAlias, $this->_name, $column);
$select->joinLeft($joinTable, $condition, array());
}
$select->setIntegrityCheck(false)->columns($columns);
}
return $select;
}