edsills
(Edsills)
February 19, 2018, 3:58pm
1
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?
softark
(Softark)
February 19, 2018, 4:10pm
2
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
edsills
(Edsills)
February 19, 2018, 4:23pm
3
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?
softark
(Softark)
February 19, 2018, 11:41pm
4
$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,
]);