Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Access Control based on value of related field

default discord avatar
daddaaff3 years ago
9

Is there a way for the access control "read" function to allow access based on the value of a a related document?



@281120856527077378

Any idea for this as well? Same use-case, just for reading.

  • discord user avatar
    jarrod_not_jared
    3 years ago

    For this you could use a where query, yeah?

  • default discord avatar
    daddaaff3 years ago

    No, it seems like it does not resolve relations. So I can only compare the string saved in the db. But I'd like to check a field from the related document.

  • discord user avatar
    jarrod_not_jared
    3 years ago

    Can you share your query attempt?

  • default discord avatar
    daddaaff3 years ago

    // "subforums" collection


    {


    name: "public",


    type: "checkbox"


    }



    // "post" collection


    {


    name: "subforum",


    type: "relationship",


    relationshipTo: "subforums"


    }



    // query constraint


    return {


    subforum: {


    public: {


    equals: true


    }


    }

  • discord user avatar
    jarrod_not_jared
    3 years ago

    Can you try “subform.public”: { equals: true }

  • default discord avatar
    daddaaff3 years ago

    Works! Thank you so much.



    It's amazing that you guys provide such great support

  • default discord avatar
    domosaurus3 years ago

    does this sort of thing work for graphql queries too?

  • default discord avatar
    daddaaff3 years ago

    I think this distinction is worth being mentioned in the docs.

  • discord user avatar
    jarrod_not_jared
    3 years ago

    it does not, nested queries are not currently supported. But its on the roadmap:

    https://github.com/payloadcms/payload/discussions/761

    I agree with ya there

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.