Skip to content

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

@allafa70

Description

@allafa70

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions