Yii2依赖下拉列表不适用于内部联接

我有三个表:

  1. kecamatan, attributes: id_kecamatan (PK), kode_kecamatan, nama_kecamatan, kode_kabupaten
  2. perusahaan, attributes: username (PK), kode_kabupaten, id_kecamatan, id_kelurahandesa, and so on.
  3. kelurahandesa, attribtues: id_kelurahandesa (PK), kode_kelurahandesa, nama_kelurahandesa, kode_kecamatan, kode_kabupaten.

So I want to create a dependent dropdown for kelurahandesa, it should display kode_kelurahandesa and nama_kelurahandesa based on the kode_kecamatan the user chooses, and only if the id_kelurahandesa is found in table perusahaan.

SQL应该看起来像这样:

SELECT `kelurahandesa`.* FROM `kelurahandesa` INNER JOIN `perusahaan` ON `kelurahandesa`.`id_kelurahandesa` = `perusahaan`.`id_kelurahandesa` WHERE (`kelurahandesa`.`kode_kabupaten`='1771') AND (`kelurahandesa`.`kode_kecamatan`='020') ORDER BY `id_kelurahandesa`

我是这样看的:

<?=
    $form->field($model, 'id_kelurahandesa')->widget(DepDrop::classname(), [
        'options' => ['id' => 'kelurahandesa-id',],
        'pluginOptions' => [
            'depends' => ['kecamatan-id'],
            'placeholder' => Yii::t('app', 'Kelurahan/Desa ...'),
            //'url' => Url::to(['perusahaan/tampilkelurahan'])
            'url' => Yii::$app->request->hostInfo . '/sidubes/' . Yii::$app->controller->id . '/tampilkelurahan',
        ]
    ]);
    ?>

并在控制器中:

$jum = \app\models\Kelurahandesa::find()
                    ->innerJoinWith('company', 'kelurahandesa.id_kelurahandesa = perusahaan.id_kelurahandesa')
                    ->select('id_kelurahandesa, nama_kelurahandesa')
                    ->where(['kelurahandesa.kode_kabupaten' => $kodekab, 'kelurahandesa.kode_kecamatan' => $kodekec])
                    ->distinct()
                    ->count();
$kecamatan = \app\models\Kelurahandesa::find()
                   ->innerJoinWith('company', 'kelurahandesa.id_kelurahandesa = perusahaan.id_kelurahandesa')
                    ->where(['kelurahandesa.kode_kabupaten' => $kodekab, 'kelurahandesa.kode_kecamatan' => $kodekec])
                    ->distinct()
                    ->orderBy('id_kelurahandesa')
                    ->all();
for ($i = 0; $i < $jum; $i++) {
                //$out = ['id' => $kecamatan[$i]['id_kecamatan'], 'name' => $kecamatan[$i]['nama_kecamatan']];
                $out[] = ['id' => $kecamatan[$i]['id_kelurahandesa'], 'name' => $kecamatan[$i]['kode_kelurahandesa'] . ' ' . $kecamatan[$i]['nama_kelurahandesa']];
}

结果下拉列表中没有列表。

所以我在视图上尝试了一下,看看内部联接是否直接起作用。

<?=
        $form->field($model, 'id_kelurahandesa')->dropDownList(ArrayHelper::map(\app\models\Kelurahandesa::find()
                ->innerJoinWith('company', 'kelurahandesa.id_kelurahandesa = perusahaan.id_kelurahandesa')
                                ->where(['kelurahandesa.kode_kabupaten' => $kodeuserPPKK, 'kelurahandesa.kode_kecamatans' => '020'])
                                ->orderBy('id_kelurahandesa')
                                ->all(), 'id_kelurahandesa', function($model) {
                    return $model->kode_kelurahandesa . ' ' . $model->nama_kelurahandesa;
                }), ['id' => 'sssss-id', 'prompt' => 'Kelurahan/Desaa...'])
        ?>

而且有效。

我还通过删除此行来检查相关的下拉代码是否在没有内部联接的情况下工作:

->innerJoinWith('company', 'kelurahandesa.id_kelurahandesa = perusahaan.id_kelurahandesa')

它也可以。

所以我的猜测是内部联接在视图中起作用,但在控制器中不起作用。我想念什么?