How to get all the children records associated with a list of parents records ?

I have 2 Entities A - B.  A is the parents, one A can have many B related to it. In mendix studio, if I have 1 object A, I can retrieve a List of B via associations.  Now when I have a List of A, I don’t know how to retrieve List of all the B that related to those objects inside List of A. Is there a way to do this other than looping through the List of A and retrieve a List of B each time? p/s : for a reference, In salesforce, I can use SOQL for a list of sObject through a reference field with   
2 answers

Is there anything that the objects of List of A have in common?

Then you could do a database retrieve on entityB with something like the following xpath:



Hi Xuan, 

I have been facing this issue multiple times. The solution depends also on what you want to do with the parents. 
For Example:

  • You got a list of EntityA and you want to perform some actions via loop on EntityA
  • In the loop you need the children (EntityB) for EntityA. As you said retrieve  in the loop is not an option
  • But you can do the following: 
  1. Retrieve all EntityB objects before performing the loop
  2. Inside the loop filter the ListOfEntityB on the association EntityA_EntityB

Now you have all Children of EntityA in your loop without having to perform extra database retrievals. 

Note that this approach could lead to java heap problems for large amounts of objects.