Local API: trying to query other collections have a matching relationship field

default discord avatar
brass_monkee
last month

post.docs[0].project is a previous resolved query.



const connectedPostsQuery = await payload.find({
      collection: 'posts',
      where: {
        project: {
          equals: post.docs[0].project,
        },
      },
    })

is is possible to access nested properties with local API?



Figured it out. it was enough to compare "project" directly to


post.docs[0].project.id


since the type was

string | Project

(thank you TypeScript!)


example for the next person:



const connectedPostsQuery = await payload.find({
      collection: 'posts',
      where: {
        project: {
          equals: post.docs[0].project.id,
        },
      },
    })
    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.