Resolve linked collection data as children

Hi all,

I’m creating an org chart feature for one of my projects where i’m using the ‘Multiple Collection Link’ add-on field to set up the relationships between 2 different collections (companies & employees). It will show the structure of each company and its employees - for example, Director → Manager → Supervisor → Employee ect…

When fetching the data, I get the necessary company with its first associated employees and all their data by setting populate to 1 in my header, but then any children who are linked to these top level people, aren’t getting their content passed on the api - just returning the ‘id’, ‘link’ and ‘display fields’.

Setup for both companies and employees collections (holds all data passed down through employees)

{
  "links": [
    {
      "name": "employees",
      "display": "name",
      "multiple": "true"
    }
  ],
  "viewMode": "list"
}

Only top level employees that have been created should be linked directly to the company, then employees below these top level people will have their own employees attached to them when necessary.

My inital fetch:

 const [pageData, setPageData] = useState({});

    useEffect(()=>{
        fetch(`/api/collections/get/companies?token=${process.env.REACT_APP_API_TOKEN}`,{
            method: 'get',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                populate: 1,
            })
        })
        .then(res => res.json())
        .then((res)=>{
            setPageData(res.entries[0]);
            console.log(pageData);
        })
        
    },[])

Based on ‘Company A’ having 3 directors with only 2 employees reporting to ‘Director B’. Only the entries under the first fetched collection have the resolved linked collection data, where i need to have all entries containing this linked data, rather then just the display and reference.

Returns an example of:

// The whole fetch of an entry under 'companies' collection
{
   name: "Company A",
   // The top level people i am displaying at the top of the org chart with no people above them
   // Defined under 'employees' collection but linked via the linked collection field
   children: [
      {name: "Director A", contains full data},
      {name: "Director B", 
         // The employees that report to this particular top level person - data isn't being pulled in by setting populate to 1
         // These children employees are linked to greater employees all under the same 'employees' collection
         children: [
           {display: 'name 1', need full data here...},
           {display: 'name 2', need full data here...}
         ],
       contains full data
      },
      {name: "Director C",contains full data}
   ],
   info: null,
   relationship: "001",
   structure: null,
   _by: "60b74b53633438fa840002a8",
   _created: 1622706830,
   _id: "60b88a8e343330840100035c",
   _mby: "60b74b53633438fa840002a8",
   _modified: 1622712667,
}

Hopefully this makes sense and of course any help would be greatly appreciated, thanks!

Never mind, I changed ‘populate’ to a higher number and it seems to be working!

May be you must fetch 2 times (companies and employee ) like fetch companies then fetch employee filter _id = companies.employee._id