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

Problems with the new "alias" function (Yii 2.0.7) #25

Open
allafa70 opened this issue Feb 19, 2016 · 0 comments
Open

Problems with the new "alias" function (Yii 2.0.7) #25

allafa70 opened this issue Feb 19, 2016 · 0 comments

Comments

@allafa70
Copy link

Hi,
there is an issue with the new alias() function in Yii 2.0.7.

If you use an alias for the primary table the function anyTagValuesin the class TaggableQueryBehavior returns an error.

I think you should change the function in this way:

public function anyTagValues($values, $attribute = null)
    {
        $model = new $this->owner->modelClass();
        $query = $this->owner;
        $tagClass = $model->getRelation($model->tagRelation)->modelClass;

        $this->owner
            ->innerJoinWith($model->tagRelation, false)
            ->andWhere([$tagClass::tableName() . '.' . ($attribute ?: $model->tagValueAttribute) => $model->filterTagValues($values)])
            ->addGroupBy(array_map(function ($pk) use ($model,$query) {
                return array_search($model->tableName(),$query->from) . '.' . $pk;
            }, $model->primaryKey()));

        return $this->owner;
    }

You don't have to get the table name from $model->tableName()but from the $from variable in the ActiveQuery object.

regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant