/** * @param $path string * @param $prefix string * @return string */ public function buildColumn($path, $prefix = '') { $join = $this->joins->add($path); $link_join = $this->joins->getIdLinkJoin($path); if (isset($link_join)) { $column = $link_join->foreign_alias . DOT . 'id'; } elseif (isset($join)) { if ($join->type === Join::LINK) { $column = $join->foreign_alias . DOT . BQ . rLastParse($path, DOT, 1, true) . BQ; } else { $property = $this->joins->getStartingClass()->getProperty($path); $column = $property && $property->getAnnotation('link')->value == Link_Annotation::COLLECTION ? $join->master_column : $join->foreign_column; $column = $join->foreign_alias . DOT . BQ . $column . BQ; } } else { list($master_path, $foreign_column) = Builder::splitPropertyPath($path); if (!$master_path && $foreign_column == 'id') { $class = $this->joins->getStartingClassName(); $i = 0; while ($class = (new Link_Class($class))->getLinkedClassName()) { $i++; } $tx = 't' . $i; } else { $tx = 't0'; } $column = !$master_path || $master_path === 'id' ? $tx . DOT . BQ . $prefix . $foreign_column . BQ : $this->joins->getAlias($master_path) . DOT . BQ . $prefix . $foreign_column . BQ; } return $column; }