Inverse relations - Reverse relationships queries

Hey Tommy,

Thanks for posting this question! Yes, it is possible to query by relationship, both ways.

I understand that in this example you have:

  • products
  • posts, which link to products

Querying all of the products for each post is relatively straightforward. When you query a post, you will get all of the product links, which include the metadata about each product. If you use fetchLinks, GraphQuery, or GraphQL, you can fetch the products. (Let me know if you'd like more info about how to do that.)

To get all of the posts by product, you can do a query by content relationship. Here's the documentation for how to do that with JavaScript and the Rest API.

To query by Content Relationship, you need the document ID of the product, so you need to make two queries: one to get the product's ID, and then one to get all of the posts that link to that ID.

If you want to get all of the posts that link to any one of the products in the array, you would use the any predicate instead of the at predicate. If you replace any with at, your code snippet might work. (If not, let me know, and I can help debug it.)

Let me know if this makes sense, or if you have any other questions. What you are describing should be completely possible, and I'm happy to help however I can.

Best,
Sam