I’m struggling to convert this SQL query into Yii2 ActiveRecord format using andWhere conditions. The query involves a CASE statement that checks different ID fields based on user type.
SELECT * FROM `employees`
WHERE `status` = 2
AND (CASE employees.category WHEN 'supervisor' THEN employees.supervisor_id ELSE employees.staff_id END IN ('12', '45', '78', '23', '89', '56', '34', '67', '91', '28', '73', '15', '44', '66', '82', '37', '19', '58', '76', '93', '41', '84', '62', '27', '95', '38', '71', '49', '86', '33', '64', '18', '52', '79', '46', '21', '87', '59', '74', '42', '68', '96', '31', '85', '53'))
I’ve tried different approaches with ActiveRecord but can’t get the CASE logic to work properly. Any suggestions on how to handle conditional field selection in Yii2 queries?