public function __construct($id, DormTable $local, DormTable $foreign, $options = array()) { $this->id = $id; $this->tableLocal = $local; $this->tableForeign = $foreign; $this->columnsToJoin = array(); if (isset($options['columns'])) { foreach ($options['columns'] as $k => $c) { $col = new DormColumn($this->tableForeign->table . '.' . $c); $col->setAlias(is_string($k) ? $k : $this->id . ucfirst($c)); $this->columnsToJoin[] = $col; } } }
/** * Returns bind of columns, joins and group-bys. Works recursive. * * @param array * @param string Prefix of all columns * @param bool Recursively bind from tables through associations * @return DormBind */ public function getBind($requestedColumns, $assocId = '', $deep = TRUE) { $columns = $joins = $binds = array(); foreach ($requestedColumns as $k => $c) { if (is_string($k) && is_array($c)) { // columns through association if ($deep) { $assoc = $this->getAssociation($k); $binds[] = $assoc->getForeignTable()->getBind($c, $k); $binds[] = $assoc->getBind($c); } continue; } elseif (is_string($k) && is_string($c)) { // special complex column $col = new DormColumnComplex($c); $col->setAlias($assocId === '' ? $k : $assocId . ucfirst($k)); } elseif (isset($this->columnsExtensional[$c])) { // saved complex column $col = new DormColumnComplex($this->columnsExtensional[$c]); $col->setAlias($assocId === '' ? $c : $assocId . ucfirst($c)); } elseif ($c == 'count') { // special saved complex column $col = new DormColumnComplex('COUNT([' . $this->table . '].[' . $this->primaryKey . '])'); $col->setAlias($assocId === '' ? $c : $assocId . ucfirst($c)); } else { // common column $col = new DormColumn($this->table . '.' . $c); $col->setAlias($assocId === '' ? $c : $assocId . ucfirst($c)); } $columns[] = $col; } $bind = new DormBind($columns, $joins, array()); array_map(array($bind, 'add'), $binds); return $bind; }