How to query all of the objects associated to another object type

I've found guides on how to get all of the documents of a specific type or how to query all of the items in a content relationship field, but I can't find any information on how to get all of the associated objects for a specific content type. For example, I have a "Destinations" custom type that has a grouped content association to a "Filter" custom type. For the list view that will show all destination I need to get all of the filter objects that are associated to any destination. It's a many to many relationship. In a relational db like MySQL I would just do a join query, but I can't find any information here on how I can do this in Prismic.

1 Like

Hey @jeremy3 ,

Thanks for posting this question. I get that you're looking for a many-to-many relation. Does this post address your use case?

I'm pretty sure we can make this work, so if that doesn't do it, let me know why, and we can work through it :slight_smile:

Best,
Sam

@samlittlefair - Unfortunately the linked post does not answer my question. That shows an example where you want to get all the posts associated to a specific product. The scenario I'm talking about would be this: Let's say you have Products and Team Members, both of which have associated Posts. Now for my team page I want to pull in all of the Posts that are associated to any Team Member (not one specific team member). This would be a join query in traditional relational db speak. I want the intersection of all Posts and Team Members. Does that make sense?

Hey Jeremy,

To get all posts that are associated to a team member, I can think of a couple of ways.

For one, you could query all team members, create an array of team member IDs, and then query for posts where the "author" field matches any of the team member IDs in the array using the any predicate.

Alternatively, assuming that the team members are linked from a field on the "post" Custom Type that is called "author," you could query all posts that have the author field filled in, using the has predicate, and then filter the results where author.data.type is equal to "team_member" (if necessary).

Let me know if that's helpful! I'm happy to brainstorm other ways to approach this, if these methods don't quite accomplish what you need. (I think it might be possible to do this with the GraphQuery option, or with GraphQL, but I'd need to do a little more digging to find out.)

Sam

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.