Currently I'm using QueryString like so:
const stringifiedQuery = qs.stringify(
{
where: {
category: {
name: {
equals: req.query.name,
},
},
},
},
{ addQueryPrefix: true }
);
But I am still getting back all posts instead of the ones with a certain category.
Post: {
/*...*/
title,
category: Category,
/*...*/
}
Category: {
id,
name,
}
How would I write my QueryString so I only get back the posts with a certain category?
Hey @ahmetskilinc — here's how you'd do that:
const stringifiedQuery = qs.stringify(
{
where: {
'category.name': {
equals: req.query.name,
},
},
},
{ addQueryPrefix: true }
);
You have to use dot notation to query on nested relationship fields, but this should be golden!
Thank you!
Hey @jmikrut how about with an array of tags
?
Post: {
/*...*/
title,
tags: Tag[],
/*...*/
}
Tag: {
id,
name,
}
Star
Discord
online
Get dedicated engineering support directly from the Payload team.