Hi, is there another way to Shorten where()
and orWhere()
?
Example the code like :
$HrEmployeeShift_opt = ArrayHelper::map(HrEmployeeShift::find()->where(['Status' => 'Pasif'])>orWhere(['Status' => 'Rolling'])->asArray()->all(), 'Id', 'Shift');
you could use or in where
$HrEmployeeShift_opt = ArrayHelper::map(HrEmployeeShift::find()->where(['or',
['Status' => 'Pasif'],
['Status' => 'Rolling']
])->asArray()->all(), 'Id', 'Shift');
but as in both conditions is Status
you could just use array in where
$HrEmployeeShift_opt = ArrayHelper::map(HrEmployeeShift::find()->where(
['Status' => ['Pasif','Rolling']]
)->asArray()->all(), 'Id', 'Shift');
and why use arrayhelper?
use just
$HrEmployeeShift_opt = HrEmployeeShift::find()->select('Shift')->where(
['Status' => ['Pasif','Rolling']]
)->indexBy('id')->asArray()->all();
alirz23
(Ali Raza)
April 21, 2020, 8:01am
3
if you pass in an array it will create an IN query which will be equivalent to what you have
HrEmployeeShift::find() ->where(['Status' => ['Pasif','Rolling']])
DropDown Compatible Query
HrEmployeeShift::find()
->select(['Shift', 'id'])
->where(['Status' => ['Pasif', 'Rolling'])
->indexBy('id')
->column();