@givemeawhisky Get the exactly same situation. Would like sort on a related field…a refenced field…a included field?
Is this possible. Think is the same question?!
// Example:
// Database Table "Result" contain (here as pseudo-code:
// [ e
// { catRef <ReferenceField to Category>: A, ranking: 1, ...},
// { catRef <ReferenceField to Category>: A, ranking: 2, ...},
// { catRef <ReferenceField to Category>: A, ranking: 3, ...},
// { catRef <ReferenceField to Category>: B, ranking: 1, ...},
// { catRef <ReferenceField to Category>: B, ranking: 2, ...},
// { catRef <ReferenceField to Category>: C, ranking: 1, ...},
// { catRef <ReferenceField to Category>: C, ranking: 2, ...},
// ...
// ]
// Database Table "Category" contain:
// [ e
// { _id: "A", priority: 2, name: "Alpha"},
// { _id: "B", priority: 3, name: "Beta"},
// { _id: "C", priority: 1, name: "Gamma"},
// ...
// ]
// Now: would like make a query like:
let data = wixData.query("Result")
.include("Category")
.ascending("catRef.priority", ranking)
.find()
.then( (res) => {
return res.items
}
// To get items in order like:
[
{ catRef <...>: C, ranking: 1, {_id: "C", priority: 1, name: "Gamma"},
{ catRef <...>: C, ranking: 2, {_id: "C", priority: 1, name: "Gamma"},
{ catRef <...>: A, ranking: 1, {_id: "A", priority: 2, name: "Alpha"},
{ catRef <...>: A, ranking: 2, {_id: "A", priority: 2, name: "Alpha"},
{ catRef <...>: A, ranking: 3, {_id: "A", priority: 2, name: "Alpha"},
{ catRef <...>: B, ranking: 1, {_id: "B", priority: 3, name: "Beta"},
{ catRef <...>: B, ranking: 2, {_id: "B", priority: 3, name: "Beta"},
]