/** * @return \yii\db\ActiveQuery */ public function getRbacRolePermissions() { return $this->hasMany(RbacRolePermission::className(), ['rbac_role_id' => 'id']); }
/** * Load edit models * @return array */ protected function loadEditModels() { $models = []; $models['rbacRoles'] = RbacRole::find()->with(['rbacRoleI18ns' => function ($query) { $query->select(['rbac_role_id', 'title'])->onCondition(['rbac_role_i18n.i18n_id' => Yii::$app->language]); }])->all(); $models['rbacPermissions'] = RbacPermission::find()->with(['rbacPermissionI18ns' => function ($query) { $query->select(['rbac_permission_id', 'title'])->onCondition(['rbac_permission_i18n.i18n_id' => Yii::$app->language]); }])->all(); $models['rbacRolesPermissions'] = []; foreach (RbacRolePermission::find()->all() as $rbacRolePermission) { $models['rbacRolesPermissions'][$rbacRolePermission->rbac_role_id][$rbacRolePermission->rbac_permission_id] = $rbacRolePermission; $models['rbacRolesPermissions'][$rbacRolePermission->rbac_role_id][$rbacRolePermission->rbac_permission_id]->scenario = 'update'; } foreach ($models['rbacRoles'] as $rbacRole) { if (isset($rbacRole->rbacRoleI18ns[0])) { foreach ($models['rbacPermissions'] as $rbacRolePermission) { if (isset($rbacRolePermission->rbacPermissionI18ns[0]) && !isset($models['rbacRolesPermissions'][$rbacRole->id][$rbacRolePermission->id])) { $models['rbacRolesPermissions'][$rbacRole->id][$rbacRolePermission->id] = new RbacRolePermission(['scenario' => 'insert']); } } } } return $models; }