Associating three entities in a m:n relationship, e.g., employee, department,
dept_employee, is straightforward enough. However, I'm stuck on ways to remove an association and delete the (dept_employee) db record.
When the records exist in the db there is no problem because the bridging entity
dept_employee can be referenced from each of the parent entities using a prefetch
path.
but ...how can I work with entities that are new and IDs that are 0.
Here's a scenario. Employees are entered, Departments are entered, the user
clicks on an employee and is presented with a list of departments and uses a
checkbox to assign the employee to the chosen department. If one is selected, create a
new dept_employee entity, assign the employee and department and save.
What can I do if they decide to change department BEFORE the data is saved. I can't find a
solution to de-referencing the first dept_employee entity and creating a new one.
In this scenario, an employee can work for at most one department.
In my 'real world' scenario I have Passenger and Service and a bridging entity ServicePassenger with two columns being the FKeys from both parent, which together form the PKey. In this scenario there can be any number of passengers assigned (and de-assigned) to (from) a service.
I can't for the life of me find a solution to this vexing problem. Any help appreciated.