Hello to everyone
I´ve got a functionality question about the Data Import module.
Starting from this documentation point:
ImportConfiguration importConfiguration = ImportConfiguration.builder(Order.class, InputDataFormat.XLSX)
.addSimplePropertyMapping("number", "Order Number")
.addSimplePropertyMapping("amount", "Order Amount")
.addPropertyMapping(ReferenceMultiFieldPropertyMapping.builder("customer", ReferenceImportPolicy.CREATE_IF_MISSING)
.addSimplePropertyMapping("firstName", "Customer First Name")
.addSimplePropertyMapping("lastName", "Customer Last Name")
.addSimplePropertyMapping("email", "Customer Email")
.withLookupPropertyNames("firstName", "lastName")
.build())
.withPreImportPredicate(extractionResult -> {
Order order = (Order) extractionResult.getEntity();
if (order.getNumber() == null) {
return false;
} else {
order.setDate(currentDate);
return true;
}
})
.withTransactionStrategy(ImportTransactionStrategy.TRANSACTION_PER_ENTITY)
.build();
We have .withPreImportPredicate which help us to avoid duplication and also to set some attributes that are not in the imported document (XLSX in my case).
So far so good but can we set a Many-to-One attribute this way? Cause` if I try to do this… :
Order order = (Order) extractionResult.getEntity();
Customer customer = dataManager.load(Customer.class).all().one();
order.setDate(currentDate);
order.setCustomer(customer);
…only the date attribute is saved in the database.
P.D… The PropertyMapping “association way” works perffectly.
using: LATEST JMIX VERSION AND LATEST INTELLIJ VERSION TOO
Thank you in advance