CTLE-421: fixed bug caught by tests

This commit is contained in:
Tim Chamberlain
2023-05-02 10:34:48 -05:00
parent 83e628d2d6
commit 2ddf1fd5c7

View File

@ -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.actions.tables.update.UpdateInput;
import com.kingsrook.qqq.backend.core.model.data.QRecord; 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.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
/******************************************************************************* /*******************************************************************************
@ -131,12 +132,15 @@ public abstract class ChildInserterPostInsertCustomizer extends AbstractPostInse
////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
List<QRecord> recordsToUpdate = new ArrayList<>(); List<QRecord> recordsToUpdate = new ArrayList<>();
for(QRecord record : records) for(QRecord record : records)
{
Serializable primaryKey = record.getValue(table.getPrimaryKeyField());
if(record.getValue(getForeignKeyFieldName()) == null)
{ {
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// get the corresponding child record, if it has any errors, set that as a warning in the parent // // get the corresponding child record, if it has any errors, set that as a warning in the parent //
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
QRecord childRecord = insertedRecordIterator.next(); QRecord childRecord = insertedRecordIterator.next();
if(childRecord.getErrors() != null) if(CollectionUtils.nullSafeHasContents(childRecord.getErrors()))
{ {
for(String childWarning : childRecord.getErrors()) for(String childWarning : childRecord.getErrors())
{ {
@ -146,10 +150,7 @@ public abstract class ChildInserterPostInsertCustomizer extends AbstractPostInse
continue; continue;
} }
Serializable primaryKey = record.getValue(table.getPrimaryKeyField()); Serializable foreignKey = childRecord.getValue(childTable.getPrimaryKeyField());
if(record.getValue(getForeignKeyFieldName()) == null)
{
Serializable foreignKey = insertedRecordIterator.next().getValue(childTable.getPrimaryKeyField());
recordsToUpdate.add(new QRecord().withValue(table.getPrimaryKeyField(), primaryKey).withValue(getForeignKeyFieldName(), foreignKey)); recordsToUpdate.add(new QRecord().withValue(table.getPrimaryKeyField(), primaryKey).withValue(getForeignKeyFieldName(), foreignKey));
record.setValue(getForeignKeyFieldName(), foreignKey); record.setValue(getForeignKeyFieldName(), foreignKey);
rs.add(record); rs.add(record);