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:
Details
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
)
)
Resolved in https://github.com/phalcon/cphalcon/pull/14674
Thanks guys 馃憤 really excited about 4.x!
Most helpful comment
Thanks guys 馃憤 really excited about 4.x!