Issue using relation in where clause of ActiveQuery

In attempting to use the following ActiveQuery




           $query = HpcSoftwareGroupMembers::find()->joinWith(['group'])->where(['group.RESTRICTED' \

=> null])->all();

           $dataProvider = new ActiveDataProvider([

              'query' => $query,

           ]);



I get a database exception. The SQL that was generated is

The SQL being executed was:

SELECT "HPC_SOFTWARE_GROUP_MEMBERS".* FROM "HPC_SOFTWARE_GROUP_MEMBERS" LEFT JOIN "HPC_SOFTWARE_GROUPS" ON "HPC_SOFTWARE_GROUP_MEMBERS"."GROUP_NAME" = "HPC_SOFTWARE_GROUPS"."GROUP_NAME" WHERE "group"."RESTRICTED" IS NULL

The group relation in joinWith was interpreted correct, but in the where statement group doesn’t seem to have been

recognized as a relation?

Try the following:




    $query = HpcSoftwareGroupMembers::find()->joinWith(['group'])

        ->where(['HPC_SOFTWARE_GROUPS.RESTRICTED' => null])

        ->all();



Or, if you want to use an alias for the related table:




    $query = HpcSoftwareGroupMembers::find()->joinWith(['group g'])

        ->where(['g.RESTRICTED' => null])

        ->all();



Please look at the API reference of joinWith(). The first parameter $with can can specify the table alias.

http://www.yiiframework.com/doc-2.0/yii-db-activequery.html#joinWith()-detail

Either of those results in error

The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.

which, as far as I can tell, occurs before the query is attempted?




    $query = HpcSoftwareGroupMembers::find()->joinWith(['group'])

        ->where(['HPC_SOFTWARE_GROUPS.RESTRICTED' => null]);

    $dataProvider = new ActiveDataProvider([

        'query' => $query,

    ]);



Or,




    $query = HpcSoftwareGroupMembers::find()->joinWith(['group g'])

        ->where(['g.RESTRICTED' => null]);

    $dataProvider = new ActiveDataProvider([

        'query' => $query,

    ]);