Hi!

I have this query builder:

$builder = $this->modelsManager
            ->createBuilder()
            ->addFrom("Skins", "s")
            ->columns("s.id, s.hash, s.count_comments, s.count_savers, s.count_cubes, s.count_views_total, s.color_red, s.color_green, s.color_blue")
            ->where("s.hash IS NOT NULL");

And this condition:

if ($color) {
    $query = "sqrt(pow(CAST(".$color['r']."-s.color_red as signed), 2)+pow(CAST(".$color['g']."-s.color_green as signed), 2)+pow(CAST(".$color['b']."-s.color_blue as signed), 2)) as distance";
    $builder->columns($builder->getColumns().", ".$query);
    $builder->andWhere("s.color_red IS NOT NULL");
    $builder->having("distance < 150");
    $builder->orderBy("distance ASC");
}

And when i execute this in paginator:

$paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array(
    "builder" => $builder,
    "limit" => 40,
    "page" => $page
));

$items = $paginator->getPaginate();

I have this exception:

Column 'distance' doesn't belong to any of the selected models (1), when preparing: SELECT COUNT(*) [rowcount] FROM [Skins] AS [s] LEFT JOIN [StoredSkins] AS [ss] ON ss.skin_id = s.id AND ss.user_id = 15 WHERE (hash IS NOT NULL) AND (color_red IS NOT NULL) HAVING distance < 150

This is logical, because there really is no distance field, but this is not what you expect.

Can i fix it on my 1.3.2?