Cphalcon: [BUG]: QueryBuilder with virtual fields: "(column) is not part of the column map" exception thrown

Created on 30 Dec 2019  路  3Comments  路  Source: phalcon/cphalcon

In Phalcon 3.x, the following code could be used to include virtual fields in the data from an executed PhalconMvcModelQueryBuilder instance:

        $modelsManager = $di->getModelsManager();
        $builder = $modelsManager
            ->createBuilder()
            // set up alias
            ->from(['Users' => '\PhalconVirtualFields\Users'])
            ->columns([
                'Users.id',
                'Users.first_name',
                'Users.last_name',
                // virtual field:
                'name' => 'CONCAT(Users.first_name, " ", Users.last_name)',
            ]);

In Phalcon 3.x, this works as expected and the name virtual field is included in the returned data.

In Phalcon 4.x, the following exception is thrown and no data is returned:

 Uncaught Phalcon\Mvc\Model\Exception: Column 'Users_id' is not part of the column map

To reproduce
I've written a small test script that demonstrates the issue, which I've attached to this issue:

index.txt

Details

  • Phalcon version: 4.0.0 (working in 3.4.4)
  • PHP Version: 7.3.11
  • Operating System: macOS 10.15.2
  • Installation type: Compiling from source
  • Zephir version (if any): n/a
  • Server: Apache
  • Other related info (Database, table schema): example schema included
bug low

Most helpful comment

Thanks guys 馃憤 really excited about 4.x!

All 3 comments

Confirmed. Bug exists with ->toArray(), but works with ->toArray(false)

(
    [0] => Array
        (
            [Users_id] => 4
            [Users_first_name] => Roger
            [Users_last_name] => Moore
            [name] => Roger Moore
        )

    [1] => Array
        (
            [Users_id] => 5
            [Users_first_name] => Timothy
            [Users_last_name] => Dalton
            [name] => Timothy Dalton
        )

    [2] => Array
        (
            [Users_id] => 1
            [Users_first_name] => Daniel
            [Users_last_name] => Craig
            [name] => Daniel Craig
        )

    [3] => Array
        (
            [Users_id] => 2
            [Users_first_name] => Sean
            [Users_last_name] => Connery
            [name] => Sean Connery
        )

    [4] => Array
        (
            [Users_id] => 3
            [Users_first_name] => Pierce
            [Users_last_name] => Brosnan
            [name] => Pierce Brosnan
        )

)

Thanks guys 馃憤 really excited about 4.x!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yakovlev-Melarn picture Yakovlev-Melarn  路  3Comments

ismail0234 picture ismail0234  路  3Comments

gytsen picture gytsen  路  3Comments

abcpremium picture abcpremium  路  3Comments

sharptry picture sharptry  路  3Comments