
Dear colleagues,
I am working on a model driven PowerApps application.
When I create a N:N (many to many) relationship the correspondent lookup field is not being auto-created.
I need to add this lookup field, with multiple selection possibility, in one of the entities.
Could you please help me?
Thanks,
rvdias
Hi @rvdias :
Can you tell me:
Do you want to add a lookup field that related to another entity?(N:N relationship)
What you want to do with the lookup field?
I'm afraid that there will be no lookup field generated automatically when you create a many-to-many relationship.
(If you create a lookup field manually between N:N entities, the system will automatically generate a 1:N relationship between these two entities. So I suggest you don’t do this.)
Firstly, let me explain why you can’t do this :
Unlike One-to-Many or Many-to-One relationships, there is no lookup field on either side of the relationship. Instead, CDS maintains a separate hidden entity on behalf of the relationship, sometimes referred to as an associative entity or join table. There is no direct access to this entity.
We can simplify things considerably if we pick a side.
For example, there is a Many-to-Many relationships between teachers and students .From a single Student’s perspective this looks like a One-to-Many relationship and we can access the information exactly as we do any other One-to-Many relationship:
I think this link will help you a lot:
Option Sets and Many-to-Many Relationships for Canvas apps:https://powerapps.microsoft.com/en-us/blog/option-sets-and-many-to-many-relationships-for-canvas-apps/
Finally, If you just want to use the lookup field to filter the records that in the associated entity . Here is my solution for your reference:
1\add a drop down control(Dropdown1) and set it’s items property to:
Students /* Students is my custom entity*/
2\add a gallery control and set it’s items property to:
Dropdown1.Selected.teachers /* teachers is my custom entity, there is a Many-to-Many relationships between teachers and students */
Best Regards,
Bof