问题
I have made the view table with function "join" in sql. but when I try to generate the view table with gii, it was said that "Table associated with Rangkuman must have primary key", and I have made primary key with table that associated with Rangkuman. But still be like this picture
Here is Rangkuman model
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "rangkuman".
*
* @property string $Fakultas
* @property string $Departemen
* @property string $KodeMayor
* @property string $NIM
* @property integer $TahunMasuk
* @property integer $JenisKelamin
* @property integer $StatusAkademik
* @property string $Usia
*/
class Rangkuman extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'rangkuman';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['Fakultas', 'Departemen', 'NIM', 'JenisKelamin'], 'required'],
[['TahunMasuk', 'JenisKelamin', 'StatusAkademik', 'Usia'], 'integer'],
[['Fakultas', 'Departemen'], 'string', 'max' => 5],
[['KodeMayor'], 'string', 'max' => 10],
[['NIM'], 'string', 'max' => 11],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'Fakultas' => Yii::t('app', 'Fakultas'),
'Departemen' => Yii::t('app', 'Departemen'),
'KodeMayor' => Yii::t('app', 'Kode Mayor'),
'NIM' => Yii::t('app', 'Nim'),
'TahunMasuk' => Yii::t('app', 'Tahun Masuk'),
'JenisKelamin' => Yii::t('app', 'Jenis Kelamin'),
'StatusAkademik' => Yii::t('app', 'Status Akademik'),
'Usia' => Yii::t('app', 'Usia'),
];
}
}
and here is the sql code
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `rangkuman` AS select `dbintegrasi`.`ipbmst_fakultas`.`Kode` AS `Fakultas`,
`dbintegrasi`.`ipbmst_departemen`.`Kode` AS `Departemen`,
`dbintegrasi`.`akdmst_mayor`.`Kode` AS `KodeMayor`,
`dbintegrasi`.`akdmst_mahasiswadoktor`.`NIM` AS `NIM`,
`dbintegrasi`.`akdmst_mahasiswadoktor`.`TahunMasuk` AS `TahunMasuk`,
`dbintegrasi`.`ipbmst_orang`.`JenisKelaminID` AS `JenisKelamin`,
`dbintegrasi`.`akdmst_mahasiswadoktor`.`StatusAkademikID` AS `StatusAkademik`,
timestampdiff(YEAR,`dbintegrasi`.`ipbmst_orang`.`TanggalLahir`,now()) AS `Usia`
from (((((`dbintegrasi`.`akdmst_mahasiswadoktor` join `dbintegrasi`.`akdmst_mayor`
on((`dbintegrasi`.`akdmst_mahasiswadoktor`.`MayorID` = `dbintegrasi`.`akdmst_mayor`.`ID`)))
join `dbintegrasi`.`ipbmst_departemen` on((`dbintegrasi`.`akdmst_mayor`.`DepartemenID` = `dbintegrasi`.`ipbmst_departemen`.`ID`)))
join `dbintegrasi`.`ipbmst_fakultas` on((`dbintegrasi`.`ipbmst_departemen`.`FakultasID` = `dbintegrasi`.`ipbmst_fakultas`.`ID`)))
join `dbintegrasi`.`ipbmst_orang` on((`dbintegrasi`.`akdmst_mahasiswadoktor`.`NIM` = `dbintegrasi`.`ipbmst_orang`.`NIMS3Key`)))
join `dbintegrasi`.`akdref_statusakademik` on((`dbintegrasi`.`akdmst_mahasiswadoktor`.`StatusAkademikID` = `dbintegrasi`.`akdref_statusakademik`.`ID`)))
join `dbintegrasi`.`ipbref_jeniskelamin` on((`dbintegrasi`.`ipbmst_orang`.`JenisKelaminID` = `dbintegrasi`.`ipbref_jeniskelamin`.`ID`));
What should I do? Thank you
来源:https://stackoverflow.com/questions/42504811/why-cant-i-create-crud-with-gii-in-yii2