fix: support reverse-direction (ManyToOne) nested deep insert#37
Conversation
ProcessOneToMany now handles both directions: - Parent is Referenced side → sets FK on children (existing behavior) - Parent is Referencing side → creates child first, then sets FK on parent This fixes nested deep inserts like Calendar → CalendarRule → InnerCalendar where the inner relationship goes from the Referencing to the Referenced side. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the deep-insert implementation so OneToManyRelationshipMetadata relationships can be processed from either side, enabling nested deep inserts where the “parent” entity is actually on the referencing (many) side of the relationship (e.g., Calendar → CalendarRule → InnerCalendar).
Changes:
- Extend
DeepInsertProcessor.ProcessOneToManyto support reverse-direction deep insert by creating the referenced child first, then updating the parent lookup. - Add a regression test covering a nested deep insert that crosses a reverse-direction (ManyToOne) relationship.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/Digitall.Dataverse.Testing.Tests/OrganizationRequests/CreateFakeDeepInsertTests.cs | Adds a test validating reverse-direction nested deep insert sets the FK on the referencing-side parent. |
| src/Digitall.Dataverse.Testing/OrganizationRequests/DeepInsertProcessor.cs | Adjusts one-to-many deep insert handling to support both referenced-side and referencing-side parents. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| else if (metadata.ReferencingEntity == parentLogicalName) | ||
| { | ||
| // Parent is the "many" side → create child first, then set FK on parent pointing to child | ||
| foreach (var child in children.Entities) | ||
| { | ||
| var childId = state.Create(child); | ||
| var childRef = new EntityReference(metadata.ReferencedEntity, childId); | ||
|
|
||
| foreach (var child in children.Entities) | ||
| var parentUpdate = new Entity(parentLogicalName, parentId) | ||
| { | ||
| [metadata.ReferencingAttribute] = childRef | ||
| }; | ||
| state.Update(parentUpdate); | ||
| } |
Qodana Community for .NET40 new problems were found
View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2026.1.0
with:
upload-result: trueContact Qodana teamContact us at qodana-support@jetbrains.com
|
A lookup attribute can only reference one record. The N:1 (reverse) branch now throws an InvalidArgument fault when multiple children are provided, preventing silent data loss where only the last child would be linked. Also validates that the child's logical name matches metadata.ReferencedEntity. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🎉 This PR is included in version 1.1.0-beta.8 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
ProcessOneToMany now handles both directions:
This fixes nested deep inserts like Calendar → CalendarRule → InnerCalendar where the inner relationship goes from the Referencing to the Referenced side.