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

Returning the results of all models/tables in query builder join

I have this code:

return $this->modelsManager->createBuilder()
    ->from('N200\Models\ProtxLog')
    ->join('N200\Models\ProtxWmlink', 'N200\Models\ProtxWmlink.tx_id = N200\Models\ProtxLog.tx_id')
    ->where('N200\Models\ProtxLog.db_table = :db_table:')
    ->andWhere('N200\Models\ProtxWmlink.submission_id = :submission_id:')
    ->getQuery()
    ->getSingleResult(
        [
            'db_table' => $this->db_table,
            'submission_id' => $this->submission_id
        ]
    );

But my returned object only contains data from N200\Models\ProtxLog. How do I also get it to return data from the joined model, N200\Models\ProtxWmLink?

Add the columns in the select

return $this->modelsManager->createBuilder()
    ->from('N200\Models\ProtxLog')
    ->columns('N200\Models\ProtxLog.*, N200\Models\ProtxWmlink.*')
    ->join('N200\Models\ProtxWmlink', 'N200\Models\ProtxWmlink.tx_id = N200\Models\ProtxLog.tx_id')
    ->where('N200\Models\ProtxLog.db_table = :db_table:')
    ->andWhere('N200\Models\ProtxWmlink.submission_id = :submission_id:')
    ->getQuery()
    ->getSingleResult(
        [
            'db_table' => $this->db_table,
            'submission_id' => $this->submission_id
        ]
    );