Hi
I'm getting a problem with many-to-many on creating new objects.
Essentially the many-to-many table update is failing because the initial "parent" record is not present when it gets to write the link table.
I'm having to use this pattern to circumvent it:
def partSave(trip: Trip): Validated[Trip] = {
val savedActivities = trip.activities
// logger.debug(s"partSave trip: trip" +
trip.id)
val trip2 = trip.copy(activities = Set.empty)
for {
trip3 <- MapperD.create(tripDao, trip2) // saves the record without the associated set of things
trip5 <- MapperD.update(tripDao, trip3, trip) // updates the record with the things back
} yield trip5
}
Oddly it was working then stopped. And in another table with the same pattern it was working fine then stopped. Is the order in which the data is written nondeterministic perhaps?
Can you give me a hint as to best logging to turn on to get a better explanation of the problem?
object TripEntity extends Entity[String, NaturalStringId, Trip] {
override val databaseSchema = DefaultPersist.schema
val id = key("id") to (_.id)
val solution_id = column("solution_id") to (_.solutionId)
val name = column("name") to (_.name)
val resourceSet = manytoone(ResourceSetEntity) to (_.resourceSet)
val activities = manytomany(ActivityEntity) join("trip_activities", "trip_id", "activity_id") to (_.activities)
def constructor(implicit m: ValuesMap) = new Trip(id,
name,
resourceSet,
activities
) with NaturalStringId
}
Tim