Skip to content

Commit 5078a70

Browse files
authored
Updating order order of variable evaluation in Multiple create order helper (#2195)
## Why make this change? The variables `doesSourceBodyContainAnyRelationshipField` and `doesTargetBodyContainAnyRelationshipField` were updated after the checks based on them were performed. Instead, they should be updated before the checks are performed. ## What is this change? Moved the updation of variables before the checks are performed. ## How was this tested? NA
1 parent 72e93af commit 5078a70

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Core/Resolvers/MultipleCreateOrderHelper.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,20 @@ private static string DetermineReferencingEntityBasedOnRequestBody(
220220
if (doesSourceContainAnyAutogenRelationshipField && doesTargetContainAnyAutogenRelationshipField)
221221
{
222222
throw new DataApiBuilderException(
223-
message: $"Both source entity: {sourceEntityName} and target entity: {targetEntityName} contain autogenerated fields for relationship: {relationshipName} at level: {nestingLevel}",
223+
message: $"Cannot execute multiple-create because both the source entity: {sourceEntityName} and the target entity: " +
224+
$"{targetEntityName} contain autogenerated fields for relationship: {relationshipName} at level: {nestingLevel}",
224225
statusCode: HttpStatusCode.BadRequest,
225226
subStatusCode: DataApiBuilderException.SubStatusCodes.BadRequest);
226227
}
227228

229+
// Determine whether the input data for source/target contain a value (could be null) for this pair of relationship fields.
230+
bool doesSourceBodyContainThisRelationshipField = columnDataInSourceBody.TryGetValue(relationshipFieldInSource, out IValueNode? sourceColumnvalue);
231+
bool doesTargetBodyContainThisRelationshipField = columnDataInTargetBody.TryGetValue(relationshipFieldInTarget, out IValueNode? targetColumnvalue);
232+
233+
// Update whether input data for source/target contains any relationship field.
234+
doesSourceBodyContainAnyRelationshipField = doesSourceBodyContainAnyRelationshipField || doesSourceBodyContainThisRelationshipField;
235+
doesTargetBodyContainAnyRelationshipField = doesTargetBodyContainAnyRelationshipField || doesTargetBodyContainThisRelationshipField;
236+
228237
// If the source entity contains a relationship field in request body which suggests we perform the insertion first in source entity,
229238
// and there is an autogenerated relationship field in the target entity which suggests we perform the insertion first in target entity,
230239
// we cannot determine a valid order of insertion.
@@ -247,14 +256,6 @@ private static string DetermineReferencingEntityBasedOnRequestBody(
247256
subStatusCode: DataApiBuilderException.SubStatusCodes.BadRequest);
248257
}
249258

250-
// Determine whether the input data for source/target contain a value (could be null) for this pair of relationship fields.
251-
bool doesSourceBodyContainThisRelationshipField = columnDataInSourceBody.TryGetValue(relationshipFieldInSource, out IValueNode? sourceColumnvalue);
252-
bool doesTargetBodyContainThisRelationshipField = columnDataInTargetBody.TryGetValue(relationshipFieldInTarget, out IValueNode? targetColumnvalue);
253-
254-
// Update whether input data for source/target contains any relationship field.
255-
doesSourceBodyContainAnyRelationshipField = doesSourceBodyContainAnyRelationshipField || doesSourceBodyContainThisRelationshipField;
256-
doesTargetBodyContainAnyRelationshipField = doesTargetBodyContainAnyRelationshipField || doesTargetBodyContainThisRelationshipField;
257-
258259
// If relationship columns are present in the input for both the source and target entities,
259260
// we cannot choose one entity as the referencing entity. This is because for a referencing entity,
260261
// the values for all the referencing fields should be derived from the insertion in the referenced entity.

0 commit comments

Comments
 (0)