We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

[Bug] QueryBuild uses wrong columnMap when there are multiple sources

Phalcon 2.0.1 / Php 5.5.12-2ubuntu4.4 / Ubuntu 14.10

I am using the QueryBuilder together with Paginator.

Here is my original code:

    public function getOrgIssueList($org_id, $page = 1, $limit = 20)
    {
        $builder = $this->getModelsManager()->createBuilder()
            ->columns('i.*')
            ->from(array('i' => 'GQ\Models\Issue', 'p' => 'GQ\Models\Paper'))
            ->where('i.paper_id=p.id')
            ->andWhere('p.org_id=' . $org_id)
            ->orderBy('issue DESC');

        $paginator = new QueryBuilder(array(
            "builder" => $builder,
            "limit" => $limit,
            "page" => $page
        ));

        return $paginator->getPaginate();
    }

Everything looks fine, but I got the strange error while fetching results from the Paginator.

Column 'paper_id' is not part of the column map

As I took a deep look inside the resultset, I found the _columnMap was set to the ColumnMap of GQ\Models\Paper rather than GQ\Models\Issue (which was desired).

QuickFix:

//reverse the array in the 'from' syntax 
            ->from(array('i' => 'GQ\Models\Issue', 'p' => 'GQ\Models\Paper'))
//to
            ->from(array('p' => 'GQ\Models\Paper', 'i' => 'GQ\Models\Issue'))

And everything was fine by now. But I still think it is a problem need to be solved.

Could you please try again using Phalcon 2.0.3 (master branch)?