System Information
- Strapi Version: 14.15.5
- Operating System: macOS sonoma 14.5
- Database: postgresql
- Node Version: 18.20.2
- NPM Version: 10
Hi everyone,
I’m facing a challenge with constructing a query in Strapi that sorts, filters and populates nested fields for my content types. Below are the details of my content types and the query requirements.
Content Types:
- University
id
title
slug
noOfStudentsStudying
createdAt
updatedAt
publishedAt
authorName
rankingStreams
(Relation with RankingStream)
- RankingStream
id
rankingYear
description
rankingNumber
stream
(Relation with Stream)rankingPublisher
(Relation with RankingPublisher)
- Stream
id
slug
- RankingPublisher
id
slug
Query Requirements:
I need to fetch universities and their associated ranking streams, filtering the ranking streams based on specific conditions. The query needs to:
- Populate
rankingStreams
withrankingNumber
andrankingYear
. - Further populate
rankingStreams.stream
withslug
andid
. - Further populate
rankingStreams.rankingPublisher
withslug
. - Filter
rankingStreams
based onrankingPublisher.slug
andstream.slug
. - Sort the results by
rankingStreams.rankingNumber
in ascending order. - Ensure only non-null
rankingNumber
andrankingStreams.id
are considered.
Here is the query I attempted:
&populate[rankingStreams][fields][0]=rankingNumber
&populate[rankingStreams][fields][1]=rankingYear
&populate[rankingStreams][populate][stream][fields][0]=slug
&populate[rankingStreams][populate][stream][fields][1]=id
&populate[rankingStreams][populate][rankingPublisher][fields][1]=slug
&populate[rankingStreams][filters][rankingPublisher][slug][$eq]=${rankingParam}
&populate[rankingStreams][filters][stream][slug][$eq]=${params.stream}
&populate[rankingStreams][sort][0]=rankingNumber:asc
&filters[rankingStreams][rankingNumber][$notNull]=true
However, this query isn’t yielding the expected results. Either the data is empty or the filtering isn’t working as intended.
Could someone guide me on how to correctly construct this query using Strapi’s query builder or qs
package or LHS ? Any help or pointers would be greatly appreciated!
Thank you!