# exposed

John Coleman

11/23/2023, 10:29 AM
Another question on 1 to many is how to sync the changes from my domain class, here for example I will delete all the related legs using the foreign key and then insert a fresh set. This is not so bad for this particular case, but would not be a solution if the legs were actually modified, maybe some being deleted, some new or some changed. How could that be implemented?
Copy code
private fun update(cargo: Cargo) {
    mapDeliveryFields(CargoEntity[!!], cargo)
    if (cargo is Cargo.Routed) {
        Legs.deleteWhere { cargoId eq!! }
        cargo.itinerary.legs.forEach {
   = {
                loadTime = it.loadTime.toKotlinDateTime()
                unloadTime = it.unloadTime.toKotlinDateTime()
                loadLocation = LocationEntity[!!]
                unloadLocation = LocationEntity[!!]
                voyage = VoyageEntity[!!]
                this.cargo = CargoEntity[!!]