-1

References from here 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'
);

[UPDATE] SOLVED

Comparing same column for two values or more for the best solution in my opinion is to use IN Condition where we can clearly see the detailed code or you can also use OR or directly build it like ->where(['Status' => ['Pasif', 'Rolling']])

Code with IN :

$HrEmployeeShift_opt = ArrayHelper::map(
    HrEmployeeShift::find()->where(
        [
            'IN',
            'Status',['Pasif', 'Rolling']
        ]
    )
    ->asArray()->all(), 'Id', 'Shift'
);
Aldan
  • 674
  • 9
  • 23

2 Answers2

2

Since you are comparing same column for two values. I guess IN Condition will also wok.

HrEmployeeShift::find()
    ->where(['Status' => ['Pasif', 'Rolling']])
   ->asArray()
   ->all();

OR

HrEmployeeShift::find()
    ->where(['IN', 'Status', ['Pasif', 'Rolling']])
   ->asArray()
   ->all();

This will result in a condition Status IN ('Pasif', 'Rolling').

Insane Skull
  • 9,220
  • 9
  • 44
  • 63
1

Posted from my mobile you are looking to do it the following way

$HrEmployeeShift_opt = ArrayHelper::map(
    HrEmployeeShift::find()->where(
        [
            'OR',
            ['Status' => 'Pasif'],
            ['Status' => 'Rolling'],
        ]
    )->asArray()->all(),
    'Id',
    'Shift'
);
Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68