public function getForeignTable($fkValue = NULL) { if (isset($fkValue)) { $table = clone $this->tableForeign; $table->setFilter(new DormFilter(array($this->columnForeign->getPlain() => $fkValue), NULL)); return $table; } else { return $this->tableForeign; } }
/** * 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; }
public function appendTo(DibiFluent $query) { return $query->groupBy($this->column->getEscaped()); }