-
Hello, I have a When a customer is authenticated, I wanted to be able to query only its own I already have entries of bills assigned to specific customer but still empty response.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hey @eudora-fabia — you're close to being there! So, your fields: [
{
label: 'Customer',
name: 'customer_id',
type: 'relationship',
relationTo: ['customers'], // set up for MANY relations
required: true,
index: true,
},
], Setting your customer_id: {
relationTo: 'customers',
value: '609490aa305c5c6a913d30bc',
}, When you have multiple
Now, in contrast, I suspect that your fields: [
{
label: 'Customer',
name: 'customer_id',
type: 'relationship',
relationTo: 'customers', // set up for ONE relation
required: true,
index: true,
},
], The data would be saved in a simpler format in the database, because we know that the related collection is always customer_id: '609490aa305c5c6a913d30bc', So, to query on this data, you'd do:
Does this answer your question? |
Beta Was this translation helpful? Give feedback.
-
This is something I came upon the other day. Would be nice to make it clearer that there is a significant difference between |
Beta Was this translation helpful? Give feedback.
-
This is actually a great call. If you are ever planning to add more relationships, or even a remote possibility exists that you might, it'll be easier over the longer term to just start out with This is about to go in the docs for sure! |
Beta Was this translation helpful? Give feedback.
Hey @eudora-fabia — you're close to being there!
So, your
customer_id
field is actually set up with an array of relations:Setting your
relationTo
as an array, as you've done, will create the following field data structure in your database:When you have multiple
relationTo
s, we also need to store the collection slug that contains the rela…