I have two entities Parent and Child with a composition. Also created default edit screens.
@JmixEntity
@Table(name = "PARENT")
@Entity(name = "Parent")
class Parent {
@JoinColumn(name = "PROP_ID")
@Composition
@OneToMany(mappedBy = "parentField")
var property: Child? = null
}
----
@JmixEntity
@Table(name = "CHILD")
@Entity(name = "Child")
class Child {
...
}
I would like the Child edit screen to be saved independently from the parent edit screen (with two independent dataContext).
Removing the @composition does the job but the 2 entites have a composition relation in terms of relational DB.
Meanwhile I think I prefer that the child screen itself choose to save or not. Not having the entity decide for the screen behavior. I may need multiple screens on the same entity with different saving behaviors in the future.
So I tried to remove the parent dataContext in the childScreen to make it independent but I got an exception.
@Subscribe
private fun onInit(event: InitEvent) {
dataContext.parent = null
}
Is there a correct way to let the child edit screen itself decide its behavior regarding saving ?
I try to keep a simple code as much as I can. I could maybe open the screen programmatically and not call .withParentDataContext()
but it would not be a proper solution to implement all throughout the app.