Retrieve over associations

0
Hi folks   What is the best approach to retrieve data in a microflow for the following scenario: Entity A has an entry In the microflow we have the parameter. Now, the case in A has an association with B. It is a 1 to many, so many B. Entity B has an association with C. It is a many to many.   How can I retrieve all C's for the parameter provided? It seems in Xpath, you cannot apply a list based on a list.   Any suggestion is more than welcome. Regards Felix
asked
2 answers
1

It is possible to retrieve data over multiple assocations. Make sure to use ctrl + space when you are going to work with xPath. It helps you with suggestions for your next steps.

 

- Add the retrieve from database activity and select the entity you want to retrieve (Entity C). It means that in your domain model the entity C will be you starting point for your xPath.

 

- From there you need to go over association to entity B.

Part 1 > [ModuleName.B_C/ 

or 

Part 1 > [ModuleName.C_B/

 

This depends of the direction for your many to many association.

 

- Then you will be in Entity B.

Part 1 & 2  > [ModuleName.B_C/ModuleName.B/

 

- From Entity B you want to go over assocation and compare it with your $A object.

Part 1,2 & 3 > [ModuleName.B_C/ModuleName.B/ModuleName.B_A = $A]

 

If you want to learn more about xPath, take a look at this learning path

https://learn.mendix.com/link/paths/62/Constrain-Your-Data-Using-XPath

answered
0
  1. First, retrieve the A entity with the given parameter:.
  2. Next, retrieve all related B entities for the A entity.
  3. Now, you can use a Java action or a custom microflow to retrieve all C entities associated with each B entity. Since you mentioned that it's a many-to-many relationship, you might need to use a sub-microflow or a Java action to handle multiple associations between B and C.

Using Microflow it will be straight easy.

Using java Action :

1] param A_entity : Entity_A;

result = retrieve(Entity_A, 'id = {param A_entity.id}');

2] public list C_entities(Entity_B b_entity) {    return retrieve(Entity_C, 'Entity_B_C.Entity_B = {param b_entity}');}

3]param A_entity : Entity_A;result_B = retrieve(Entity_B, 'Entity_A_B.Entity_A = {param A_entity}');

4] result = list();for (b in result_B) {    result = result.addAll(C_entities(b));}return result;

answered