Skip to content

How to Query relationship field #187

Answered by jmikrut
jbalatero asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @eudora-fabia — you're close to being there!

So, your customer_id field is actually set up with an array of relations:

	fields: [
           {
              label: 'Customer',
              name: 'customer_id',
              type: 'relationship',
              relationTo: ['customers'], // set up for MANY relations
              required: true,
              index: true,
            },
	],

Setting your relationTo as an array, as you've done, will create the following field data structure in your database:

customer_id: {
  relationTo: 'customers',
  value: '609490aa305c5c6a913d30bc',
},

When you have multiple relationTos, we also need to store the collection slug that contains the rela…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@jbalatero
Comment options

Answer selected by jbalatero
Comment options

You must be logged in to vote
2 replies
@jmikrut
Comment options

@Ontopic
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants