J'ai un modèle TblPayroll
avec les attributs ci-dessus, je veux vérifier l'unicité de 'fk_int_emp_id'
, 'fk_int_payroll_month'
, 'fk_int_payroll_year'
. Si ce trois champs déjà dans la base de données, il ne doit pas insérer. Au moins un est différent qu'il devrait insérer. Comment puis-je vérifier l'unicité?Comment définir 3 attribut est unique de modèle
public function attributeLabels()
{
return [
'pk_int_payroll_id' => 'Payroll Id',
'fk_int_emp_id' => 'Employee',
'vchr_worked_hours' => 'Worked Hours',
'vchr_actual_hours' => 'Actual Hours',
'fk_int_payroll_month' => 'Month',
'fk_int_payroll_year' => 'Year',
];
}
public function rules()
{
return [
[[ 'vchr_worked_hours', 'vchr_actual_hours', 'fk_int_payroll_month', 'fk_int_payroll_year'], 'required'],
//[['fk_int_emp_id', 'fk_int_payroll_year','vchr_worked_hours','vchr_actual_hours'], 'integer'],
//[['fk_int_emp_id','fk_int_payroll_month','fk_int_payroll_year'], 'string', 'max' => 50],
[['fk_int_emp_id'], 'exist', 'skipOnError' => true, 'targetClass' => TblEmployee::className(), 'targetAttribute' => ['fk_int_emp_id' => 'pk_int_emp_id']],
[['fk_int_payroll_month'], 'exist', 'skipOnError' => true, 'targetClass' => TblPayrollMonth::className(), 'targetAttribute' => ['fk_int_payroll_month' => 'pk_int_payroll_month_id']],
[['fk_int_payroll_year'], 'exist', 'skipOnError' => true, 'targetClass' => TblPayrollYear::className(), 'targetAttribute' => ['fk_int_payroll_year' => 'pk_int_payroll_year_id']],
];
}
@scaiseEdge vérifier ce que vous avez défini –
attribut unique dans les règles non étiquettes, montrent la section règles nous. –
s'il vous plaît vérifier les édités, j'ai besoin d'insérer ce modèle, mais tout en insérant 'fk_int_emp_id', 'fk_int_payroll_month', 'fk_int_payroll_year' il devrait être unique à sametime. si quelqu'un de différent dans ces trois domaines, il devrait insérer ... –