You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Validation to disallow multiple create on related entities backed by same database table (#2189)
## Why make this change?
DAB doesn't support multiple-create on related entities which are backed
by same database table. This PR adds a validation to catch that scenario
and throw a meaningful exception to the end user. Issue to track
support: #2157
## What is this change?
- Adds a validation during order determination logic in
`MultipleCreateOrderHelper.GetReferencingEntityName()` method to catch
the scenario.
- In the method signature for
`MultipleCreateOrderHelper.GetReferencingEntityName()`, a new parameter
isMNRelationship is added with default value of false. The reasoning is
explained in the section.
#### Reason for why
`MultipleCreateOrderHelper.GetReferencingEntityName()` is called even
for M:N relationships when we know that we are always going to return an
empty string?
1. For M:N relationships, we assume one of the source/target entity as
the referencing entity when we do insertion during query execution
because any of the entity can be considered as the
referencing/referenced entity. However this does not hold true when the
source and target entities are backed by same database tables - in which
case we cannot consider any of the entity as the referenced/referencing
entity.
2. The not-supported use case - that of not allowing multiple-create via
relationships in which source and target entities are backed by same
database tables is because DAB cannot determine a valid order of
insertion. Since this concerns order determination, it is better to keep
the code inside the
`MultipleCreateOrderHelper.GetReferencingEntityName()` method.
3. Keeping this in `MultipleCreateOrderHelper` provides unit test
coverage even for the other 2 db types i.e. PgSql,MySql.
## How was this tested?
- Added test
MultipleCreateOrderHelperUnitTests.TestExceptionForSelfReferencingRelationships()
to test the change for the 3 dbs - MySql/MsSql/PgSql.
## Sample Request(s)
1. Config:

Request:

---------
Co-authored-by: Aniruddh Munde <[email protected]>
Co-authored-by: Sean Leonard <[email protected]>
0 commit comments