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

Table alias error #9

Closed
netsnatch opened this issue Jun 1, 2017 · 4 comments
Closed

Table alias error #9

netsnatch opened this issue Jun 1, 2017 · 4 comments

Comments

@netsnatch
Copy link

I get this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'categories.parent_id' in 'where clause'
The SQL being executed was: SELECT MAX(sort) FROM `categories` `cat` WHERE categories.`parent_id`=4

Category model:

    public static function find()
    {
        return (new CategoryQuery(get_called_class()))->alias('cat');
    }

The problem is in using $this->owner->tableName()

@paulzi
Copy link
Owner

paulzi commented Jun 1, 2017

Yii2 does not have methods for getting the current alias of query. In yii\db\ActiveQuery exist method getTableNameAndAlias(), but it's private. In main yii2 repo, there are several issue and pull-requests:
https://github.com/yiisoft/yii2/issues/7263
yiisoft/yii2#11646
Without method getTableAlias(), it is difficult to implement the getting of the current table alias and I need to duplicate this private method.
Therefore, aliases are not currently supported.

@netsnatch
Copy link
Author

I propose to delete the name of the table and leave only the name of the field.

@paulzi
Copy link
Owner

paulzi commented Jun 2, 2017

It is possible, but if you use joins, then the absence of aliases will also generate errors.
I will try to deal with this issue without waiting for a solution in the framework.

@netsnatch
Copy link
Author

Thanks

@paulzi paulzi closed this as completed Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants