Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
richmilns opened this issue Dec 30, 2019 · 3 comments
Assignees
Labels

Comments

@richmilns
Copy link

@richmilns richmilns commented Dec 30, 2019

In Phalcon 3.x, the following code could be used to include virtual fields in the data from an executed Phalcon\Mvc\Model\Query\Builder 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
@richmilns richmilns changed the title [BUG]: QueryBuilder "(column) is not part of the column map" exception with virtual fields [BUG]: QueryBuilder with virtual field columns: "(column) is not part of the column map" exception thrown Dec 30, 2019
@richmilns richmilns changed the title [BUG]: QueryBuilder with virtual field columns: "(column) is not part of the column map" exception thrown [BUG]: QueryBuilder with virtual fields: "(column) is not part of the column map" exception thrown Dec 30, 2019
@niden niden added this to Current Sprint (Ends January 10th) in Phalcon Roadmap Dec 30, 2019
@Jeckerson

This comment has been minimized.

Copy link
Member

@Jeckerson Jeckerson commented Jan 1, 2020

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

Array
(
    [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
        )

)
@niden niden added the status: low label Jan 1, 2020
Jeckerson added a commit that referenced this issue Jan 1, 2020
Jeckerson added a commit that referenced this issue Jan 1, 2020
@Jeckerson Jeckerson moved this from Current Sprint (Ends January 10th) to Working on it in Phalcon Roadmap Jan 1, 2020
Jeckerson added a commit that referenced this issue Jan 2, 2020
Jeckerson added a commit that referenced this issue Jan 2, 2020
Jeckerson added a commit that referenced this issue Jan 2, 2020
Jeckerson added a commit that referenced this issue Jan 2, 2020
@Jeckerson Jeckerson self-assigned this Jan 2, 2020
Jeckerson added a commit that referenced this issue Jan 2, 2020
Jeckerson added a commit that referenced this issue Jan 2, 2020
…n-map

#14669 - Fix alias columns in Query Builder Column map
@niden

This comment has been minimized.

Copy link
Member

@niden niden commented Jan 2, 2020

Resolved in #14674

@niden niden closed this Jan 2, 2020
Phalcon Roadmap automation moved this from Working on it to Implemented Jan 2, 2020
@richmilns

This comment has been minimized.

Copy link
Author

@richmilns richmilns commented Jan 2, 2020

Thanks guys 👍 really excited about 4.x!

@niden niden moved this from Implemented to Released in Phalcon Roadmap Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Phalcon Roadmap
  
Released
3 participants
You can’t perform that action at this time.