Controlling Order
[#order-operator-example] For Dataset Entity Attribute entity orderByDatasetEntityAttributeOperator object is created with following fields:
- active: order_by_enum
- configuration: order_by_enum
- constraint: order_by_enum
- euuid: order_by_enum
- modified_by: order_by_enum
- modified_on: order_by_enum
- name: order_by_enum
- seq: order_by_enum
- type: order_by_enum
Where order_by_enum is either asc or desc. As mentioned in OrderBy operator section, search queries accept _order_by operator that allows to fine tune result order of returned results. Order by can be used on multiple levels.
Root entity records can be sorted by any many to one or one to one relation, as shown on example below. This ordering is not limited to one level, it can be nested in query attributes to desired level.
#
Query with order of root elements by using child values{ searchDatasetEntityAttribute(_limit:10 _order_by:[{name:asc} {entity:{name:desc}}]) { name entity { name } }}
#
Response{ "data": { "searchDatasetEntityAttribute": [ { "name": "Active", "entity": { "name": "User Role" } }, { "name": "Active", "entity": { "name": "User Group" } }, { "name": "Active", "entity": { "name": "User" } }, { "name": "Active", "entity": { "name": "Dataset Entity Attribute" } }, { "name": "Avatar", "entity": { "name": "User" } }, { "name": "Cardinality", "entity": { "name": "Dataset Relation" } }, { "name": "Configuration", "entity": { "name": "Dataset Version" } }, { "name": "Configuration", "entity": { "name": "Dataset Entity Attribute" } }, { "name": "Configuration", "entity": { "name": "Dataset Entity" } }, { "name": "Constraint", "entity": { "name": "Dataset Entity Attribute" } } ] }}
When executing query that refers related entity in selection it is possible to order requested records if relation returns multiple result. This is case when entity has one to many or many to many relation. Example bellow shows how nested selection can control order of returned results.
#
Query with order of child selection{ searchDatasetEntity (name:{_eq:"Dataset Entity Attribute"}) { attributes(_order_by:{name:asc}) { name } }}
#
Response{ "data": { "searchDatasetEntity": [ { "attributes": [ { "name": "Active" }, { "name": "Configuration" }, { "name": "Constraint" }, { "name": "Name" }, { "name": "Seq" }, { "name": "Type" } ] } ] }}