1

How do I use deep in nested relations?

deep: {
    translations: { _filter: { languages_code: 'nl-NL' } },
    variants: { _filter: { translations: { languages_code: 'nl-NL' } } }, // This does not work
}

The object that I try to filter looks as this

I am trying to filter out translations inside the variants aswell. But the above query does not work.

{
    // WORKS: translations: { _filter: { languages_code: locals.language } }
    translations: [
        {
            id: 7,
            products_id: 1,
            languages_code: 'nl-NL', // locals.language = nl-NL
            title: '...',
            description: '...',
            slug: '...',
            variantTitle: null,
        },
    ],
    // DOES NOT WORK: variants: { _filter: { translations: { languages_code: locals.language } } } 
    // I guess it does not work since translations is an array inside variants
    // which is also an array
    variants: [
        {
            id: 1,
            product: 1,
            translations: [
                {
                    id: 1,
                    product_variants_id: 1,
                    languages_code: 'nl-NL',
                    title: 'Aantal',
                },
                {
                    id: 2,
                    product_variants_id: 1,
                    languages_code: 'en-US', // This object should be left out of the result
                    title: 'Amount',
                },
            ],
            products: [2, 3],
        },
    ],
}

1 Answer 1

1

If I understand correctly you have a collection that contains variants that contains translations and you try to filter the list of translations when reading the root collection.

In this case the following query should work (REST):

deep = {
  "variants": {
    "translations": {
      "_filter": {
        "languages_code": {
          "_eq": "EN"
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I already had my answer with the help of discord, but yes, this was it indeed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.