Get all records based on a reverse link lookup Next js

Is this possible at all? I’m using NextJS and graphql-request to get data from the CMS. Two of the models I’m have are:

  • Areas
  • Developments

Within the developments the client wants to assign them to an area. They do not want to use multiple links on an area. So I have a single link on each development record where they can choose one of the Area records.

Now this is fine when showing the area information on individual development pages on the front end, but there are also Area pages where we need to list all of the developments allocated to the area. On these I am looping through all developments and dividing the count meta by 100 in order to ensure I’ve checked everything (there are 800 records so far and the site is only growing).

On the home page we have all areas listed and a number showing how many developments are in each area. In order for me to do this, again, I am having to loop through count/100 and then for each development match its area to an area to count them and display how many exist.

I feel like it would be so much easier if we could just do something like looping through areas and then:

developments.filter(development => === to get the count / developments that have a link to the area.

Can it be done some way in NextJS?

Hello @joecox, and welcome to the community!

Unfortunately, that is a current limitation of our system, filtering linked records by their field values is currently not possible, but we do have it in our roadmap as you can see by this feature request: Deep filtering on both CMA and CDA

The current ways to get the behaviour you want, would be as you said, either adding a multiple links field on “Area” creating a “Double link” between area and development. Or, as you also said, request every development locally, and filtering them locally based on the Area that is linked, however that can scale quite poorly for a large number of development records.