From 2ddf1fd5c7c5d2106d22766465a66dcea41cf46d Mon Sep 17 00:00:00 2001 From: Tim Chamberlain Date: Tue, 2 May 2023 10:34:48 -0500 Subject: [PATCH] CTLE-421: fixed bug caught by tests --- .../ChildInserterPostInsertCustomizer.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/customizers/ChildInserterPostInsertCustomizer.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/customizers/ChildInserterPostInsertCustomizer.java index 3cb8691f..c8192088 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/customizers/ChildInserterPostInsertCustomizer.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/customizers/ChildInserterPostInsertCustomizer.java @@ -34,6 +34,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput; import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput; import com.kingsrook.qqq.backend.core.model.data.QRecord; import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData; +import com.kingsrook.qqq.backend.core.utils.CollectionUtils; /******************************************************************************* @@ -132,24 +133,24 @@ public abstract class ChildInserterPostInsertCustomizer extends AbstractPostInse List recordsToUpdate = new ArrayList<>(); for(QRecord record : records) { - /////////////////////////////////////////////////////////////////////////////////////////////////// - // get the corresponding child record, if it has any errors, set that as a warning in the parent // - /////////////////////////////////////////////////////////////////////////////////////////////////// - QRecord childRecord = insertedRecordIterator.next(); - if(childRecord.getErrors() != null) - { - for(String childWarning : childRecord.getErrors()) - { - record.addWarning("Error creating child " + childTable.getLabel() + " (" + childWarning + ")"); - } - rs.add(record); - continue; - } - Serializable primaryKey = record.getValue(table.getPrimaryKeyField()); if(record.getValue(getForeignKeyFieldName()) == null) { - Serializable foreignKey = insertedRecordIterator.next().getValue(childTable.getPrimaryKeyField()); + /////////////////////////////////////////////////////////////////////////////////////////////////// + // get the corresponding child record, if it has any errors, set that as a warning in the parent // + /////////////////////////////////////////////////////////////////////////////////////////////////// + QRecord childRecord = insertedRecordIterator.next(); + if(CollectionUtils.nullSafeHasContents(childRecord.getErrors())) + { + for(String childWarning : childRecord.getErrors()) + { + record.addWarning("Error creating child " + childTable.getLabel() + " (" + childWarning + ")"); + } + rs.add(record); + continue; + } + + Serializable foreignKey = childRecord.getValue(childTable.getPrimaryKeyField()); recordsToUpdate.add(new QRecord().withValue(table.getPrimaryKeyField(), primaryKey).withValue(getForeignKeyFieldName(), foreignKey)); record.setValue(getForeignKeyFieldName(), foreignKey); rs.add(record);