public function getAsQuery($forCount = false){
        $table=$model=null;
        if ($this->model) {
            $model = $this->model;
            $table = $model::getTableName();
        }
        $join = $this->getJoin($forCount);
        $group = ($group = $this->getGroup()) ? ' GROUP BY ' . $group : '';
        $having = ($having = $this->getHaving()) ? ' HAVING ' . $having : '';
        $order = ($order = $this->getOrder()) ? ' ORDER BY ' . $order : '';
        $limit = ($limit = $this->getLimit()) ? ' LIMIT ' . $limit : '';
        $procedure = ($procedure = $this->getProcedure()) ? ' PROCEDURE ' . $procedure : '';
        $into = ($into = $this->getInto()) ? ' INTO ' . $into : '';
        $for_update = $this->for_update ? ' FOR UPDATE' : '';
        $lock_in_share_mode = $this->lock_in_share_mode ? ' LOCK IN SHARE MODE' : '';
        $q = ($this->model ? "SELECT " . $this->getSelect() . " FROM `$table` as `t` " : "") . $join . " WHERE " . $this->getCondition() . $group . $having . $order . $limit . $procedure . $into . $for_update . $lock_in_share_mode;
        return $q;
    }