mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 19:58:09 +00:00
Fix mixin sorting (#905)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
5b644aac5c
commit
04efff3b49
@ -224,6 +224,8 @@ abstract class MongoAdapterBase extends TxProcessor {
|
|||||||
key += '.'
|
key += '.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check if key is belong to mixin class, we need to add prefix.
|
||||||
|
key = this.checkMixinKey<T>(key, clazz)
|
||||||
}
|
}
|
||||||
sort[key] = options.sort[_key] === SortingOrder.Ascending ? 1 : -1
|
sort[key] = options.sort[_key] === SortingOrder.Ascending ? 1 : -1
|
||||||
}
|
}
|
||||||
@ -242,6 +244,21 @@ abstract class MongoAdapterBase extends TxProcessor {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private checkMixinKey<T extends Doc>(key: string, clazz: Ref<Class<T>>): string {
|
||||||
|
if (!key.includes('.')) {
|
||||||
|
try {
|
||||||
|
const attr = this.hierarchy.getAttribute(clazz, key)
|
||||||
|
if (this.hierarchy.isMixin(attr.attributeOf)) {
|
||||||
|
// It is mixin
|
||||||
|
key = attr.attributeOf + '.' + key
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
// ignore, if
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
async findAll<T extends Doc>(
|
async findAll<T extends Doc>(
|
||||||
_class: Ref<Class<T>>,
|
_class: Ref<Class<T>>,
|
||||||
query: DocumentQuery<T>,
|
query: DocumentQuery<T>,
|
||||||
@ -260,8 +277,9 @@ abstract class MongoAdapterBase extends TxProcessor {
|
|||||||
if (options.sort !== undefined) {
|
if (options.sort !== undefined) {
|
||||||
const sort: Sort = {}
|
const sort: Sort = {}
|
||||||
for (const key in options.sort) {
|
for (const key in options.sort) {
|
||||||
|
const ckey = this.checkMixinKey<T>(key, _class)
|
||||||
const order = options.sort[key] === SortingOrder.Ascending ? 1 : -1
|
const order = options.sort[key] === SortingOrder.Ascending ? 1 : -1
|
||||||
sort[key] = order
|
sort[ckey] = order
|
||||||
}
|
}
|
||||||
cursor = cursor.sort(sort)
|
cursor = cursor.sort(sort)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user