user1983183
user1983183

Reputation: 88

Directus many-to-many returns reversed data

I have a 'products' and 'categories' colleciton, then a juntion table 'producst_categories'

On products my products_categories field is a many-to-many and configured to use the juntion table as so:

enter image description here

But when I view the response for showing all products the products_categories is returning the products_id not the categories_id

enter image description here

Upvotes: 1

Views: 1761

Answers (1)

RANGER
RANGER

Reputation: 1691

Your M2M relationship looks correct, so my guess is that your API request is only returning the parent item. If you want to fetch deeper/relational data (not just the ID/PK) then you'll need to use the fields parameter:

It uses dot-notation for the depth — with wildcards (*) for all fields, or exact field names. For example:

?fields=*.*.*

// OR...

?fields=products.categories.name

https://docs.directus.io/api/query/fields.html

https://docs.directus.io/getting-started/troubleshooting.html#why-is-my-relational-data-file-only-returning-an-id

Upvotes: 2

Related Questions