cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Espero
Regular Visitor

Creating records for N:N relationships

Hello, 

 

I've created a Model Driven app, with 2 custom entities. 

 

Then I created a Many to Many relationship between these entities. I'm aware about the intersect entity that will be created to maintain this N:N relatioship, but I don't know how to create records (multiple one) for one of the entities. 

 

so my question is: How can I create multiple records for one of these entities?

 

Thanks in advance for your help! 

1 ACCEPTED SOLUTION

Accepted Solutions

This opinion may be somewhat controversial, so make of it what you will (I come from a SQL background and have limited experience with CDS so I will admit I may be missing something here).

N:N relationships, multi-value fields and so on are not standard relational concepts. I assume they have been implemented to make designing building databases easier for users who do not understand relational modelling (CDS being promoted as a 'low code' database platform). As such, use of these features mean you will likely hit issues when you want to do things like filter or add records.

If you model the relationship 'correctly' (i.e. two parent tables and a child table that takes as foreign keys the primary keys from each parent) then adding/removing records to the child table is the same as you add records to any other table and you do not need to worry about learning any additional commands and syntax such as 'Relate' / 'Unrelate' or hit other problems where these non-standard features are not fully supported.

View solution in original post

4 REPLIES 4
GarethPrisk
Resident Rockstar
Resident Rockstar

This is easily accomplished using a canvas app, or using Flow.

 

The MDA unified client interface (UCI) is less capable for doing bulk inserts into the system table, which tracks the relationships. As you've seen, this is very intuitive for relating from one record to others.

 

What is your logic for deciding which X record is associated to which Y record? We can then decide the best way to handle it.

Let's say the use case is the following:

 

I'm maintaining a software inventory for an organization with multiple sites. Each site is using a different version of the software. 

 

I want to keep one entry for the software, but the relationship location-software owns the version used in every site. 

 

The solution I found so far is to use a custom intersec entity, on which I can created the fields I need. 

 

I'm just wondering if there is a better solution. 

This opinion may be somewhat controversial, so make of it what you will (I come from a SQL background and have limited experience with CDS so I will admit I may be missing something here).

N:N relationships, multi-value fields and so on are not standard relational concepts. I assume they have been implemented to make designing building databases easier for users who do not understand relational modelling (CDS being promoted as a 'low code' database platform). As such, use of these features mean you will likely hit issues when you want to do things like filter or add records.

If you model the relationship 'correctly' (i.e. two parent tables and a child table that takes as foreign keys the primary keys from each parent) then adding/removing records to the child table is the same as you add records to any other table and you do not need to worry about learning any additional commands and syntax such as 'Relate' / 'Unrelate' or hit other problems where these non-standard features are not fully supported.

View solution in original post

Espero
Regular Visitor

Thank you Paul! I guess that's the way I'll be proceeding. In my entire model, I have probably only 3 N:N relationships, which will be easy to maintain through a custom relationship (intersect) entity, that will exactly use the keys as you've described. 

 

I'll just wait for the feedback from @GAM to see if he have the same opinion. 

 

You help is appreciated 😉 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,072)