#community-help

Sorting Nested Fields in Schema Declaration

TLDR Ibrahim inquired how to sort by a nested object field 'name' in a schema. Jason suggested keeping only the 'product.name' part in the schema to achieve the sorting.

Powered by Struct AI

1

2
2w
Solved
Join the chat
Nov 14, 2023 (2 weeks ago)
Ibrahim
Photo of md5-a7605b093448e06efb0a1c150153cad6
Ibrahim
02:46 AM
Hi team, excited to be joining this community and to learn more!

I have a quick question, and would love some help.
So in one of my schemas, I am declaring an object field. Inside the object field, I have a field called 'name'

I want to be able to use 'sort_by' to sort by that name field.

When I declare my schema like this, it works fine
            {
                'name':  'product',
                'type':  'auto',
              
            },
            {
                'name':  'product.name',
                'type':  'string',
                'sort':True,

            },

However, this doesn't seem to work and get a 'not a sortable field' error when I try to sort by 'product.name'
            {
                'name':  'product',
                'type':  'auto',
              'fields:[
                     {
                    'name':  'product.name',
                    'type':  'string',
                    'sort':True,
                  },
                 ]
            },
          

Is my first approach correct, or is there a way to make the second approach work?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:27 AM
If you only want to sort on product.name, then just having this in the schema would suffice:

{
                'name':  'product.name',
                'type':  'string',
                'sort':True,

            },

1