Marc
09/23/2024, 12:07 PMclass ShiftDao(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<ShiftDao>(Shifts)
var date by Shifts.date
var startTime by Shifts.startTime
var endTime by Shifts.endTime
var text by Shifts.text
var isEvent by Shifts.isEvent
var client by ClientDao optionalReferencedOn Shifts.clientId
var schedule by ScheduleDao referencedOn Shifts.scheduleId
var assignees by EmployeeDao via ShiftAssignees
}
object ShiftAssignees : IntIdTable() {
val shiftId = reference("shift_id", Shifts, fkName = "fk_shiftass_shift_id")
val employeeId = reference("employee_id", Employees, fkName = "fk_shiftass_employee_id")
val attended = bool("attended").default(true)
}
My goal is to get not only all EmployeeDao's out of the assignments but also the "attended" attribute.
Is this possible?Chantal Loncle
09/23/2024, 1:46 PMIdTable
). Please consider tracking EXPOSED-320 for updates on completion.Marc
09/23/2024, 3:03 PMChantal Loncle
09/24/2024, 12:57 AMvia
, each field would be treated like a regular reference etc, but it doesn't seem very straightforward.
An alternative I experimented with, before starting the design for the feature, involves using CompositeIdTable
to define the link table. With that you could define an entity ShiftAssigneesDAO
class with a single attended
field and still use via
in ShiftDAO
, as well as an additional field for attended
.
The only caveat with this approach is that the via
field (assignees
) could only be used for retrieiving/getting. Instances of ShiftAssigneesDAO
would have to be created as usual with new()
and a CompositeID
of the 2 reference column values.
Here's an example of this approach in the tests.