An error is reported on the Order New page when a new order item is created.
It looks like a transaction colleague has committed.
I want to save the order item when I save the order
LOOK:
Hello!
In the Entity Designer try to change type of orderItem
attribute from Association
to Composition
.
Composition means that OrderItem will be exist as part of Order and will be commited with Order.
See:
Entities :: Jmix Documentation
@Composition :: Jmix Documentation
Thanks for your answer, but this is just a case. I would like to know how to save them together in the Association type. And not Combined type
Your OrderItem
editor saves the instance to the database and then returns saved item to the Order
editor.
If you need to save OrderItem only with Order, you can use commitDelegate()
function to override saving logic in OrderItem
editor.
For instance:
@Install(target = Target.DATA_CONTEXT)
private Set<Object> commitDelegate(SaveContext saveContext) {
EntitySet entitiesToSave = saveContext.getEntitiesToSave();
Collection<OrderItem> orderItems = entitiesToSave.getAll(OrderItem.class);
return Collections.singleton(orderLines.iterator().next());
}
Then this item will be saved with Order.
You can find this function in “Generate Handler” action in a top panel of controller class.
Thank you, this method works, it is possible by default in Cuba 7.2, do you know what is the principle?
CUBA 7.2 screens API works the same way. By default it will try to save instance to DB.
You can create some abstract editor screen with the method above (or override others) and inherit it in your editor screens.
Also you can create custom screen template that will contain your logic, see:
5.4.1.1. Custom Screen Templates
That’s a good idea, thanks for the reminder.