I would like to display in Gridview the following SQL command:
SELECT DISTINCT
application_floor
.*,
application_shift
.* FROM
application_floor
LEFT JOIN
application
ON
application_floor
.
application_id
=
application
.
id
LEFT JOIN
applicant
ON
application
.
applicant_id
=
applicant
.
id
LEFT JOIN
department
ON
applicant
.
department_id
=
department
.
id
LEFT JOIN
faculty
ON
department
.
faculty_id
=
faculty
.
id
LEFT JOIN
floor
ON
application_floor
.
floor_id
=
floor
.
id
LEFT JOIN
building
ON
floor
.
building_id
=
building
.
id
LEFT JOIN
application_shift
ON
application_floor
.
application_id
=
application_shift
.
application_id
LEFT JOIN
shift
ON
application_shift
.
shift_id
=
shift
.
id
But distinct() only takes in the arguments true or false. What is the best way to do this?
I’ve changed the query to include a groupBy(), so the query now looks like this:
$ query = ApplicationFloor::find()->joinWith(['application','application.applicant','application.applicant.department','application.applicant.department.faculty', 'floor','floor.building', 'applicationShift', 'applicationShift.shift'])->groupBy(['application_floor.floor_id', 'application_shift.shift_id', 'application_floor.application_id']);
The command being run seems correct:
SELECT COUNT(*) FROM (SELECT
application_floor.* FROM
application_floorLEFT JOIN
applicationON
application_floor.
application_id=
application.
idLEFT JOIN
applicantON
application.
applicant_id=
applicant.
idLEFT JOIN
departmentON
applicant.
department_id=
department.
idLEFT JOIN
facultyON
department.
faculty_id=
faculty.
idLEFT JOIN
floorON
application_floor.
floor_id=
floor.
idLEFT JOIN
buildingON
floor.
building_id=
building.
idLEFT JOIN
application_shiftON
application_floor.
application_id=
application_shift.
application_idLEFT JOIN
shiftON
application_shift.
shift_id=
shift.
idGROUP BY
application_floor.
floor_id)
But the Gridview is way out of wack and not displaying all the rows, seems to be doing the distinct rows again. Does anyone know how to fix this?