fix: MSSQL - assetFolder getHierarchy query (#1131)

pull/1163/head
apif 5 years ago committed by Nicolas Giard
parent 44a1c8699f
commit 8badd8fd55

@ -40,11 +40,21 @@ module.exports = class AssetFolder extends Model {
* @param {Number} folderId Id of the folder * @param {Number} folderId Id of the folder
*/ */
static async getHierarchy (folderId) { static async getHierarchy (folderId) {
const hier = await WIKI.models.knex.withRecursive('ancestors', qb => { let hier
qb.select('id', 'name', 'slug', 'parentId').from('assetFolders').where('id', folderId).union(sqb => { if (WIKI.config.db.type === 'mssql') {
sqb.select('a.id', 'a.name', 'a.slug', 'a.parentId').from('assetFolders AS a').join('ancestors', 'ancestors.parentId', 'a.id') hier = await WIKI.models.knex.with('ancestors', qb => {
}) qb.select('id', 'name', 'slug', 'parentId').from('assetFolders').where('id', folderId).unionAll(sqb => {
}).select('*').from('ancestors') sqb.select('a.id', 'a.name', 'a.slug', 'a.parentId').from('assetFolders AS a').join('ancestors', 'ancestors.parentId', 'a.id')
})
}).select('*').from('ancestors')
}
else {
hier = await WIKI.models.knex.withRecursive('ancestors', qb => {
qb.select('id', 'name', 'slug', 'parentId').from('assetFolders').where('id', folderId).union(sqb => {
sqb.select('a.id', 'a.name', 'a.slug', 'a.parentId').from('assetFolders AS a').join('ancestors', 'ancestors.parentId', 'a.id')
})
}).select('*').from('ancestors')
}
// The ancestors are from children to grandparents, must reverse for correct path order. // The ancestors are from children to grandparents, must reverse for correct path order.
return _.reverse(hier) return _.reverse(hier)
} }

Loading…
Cancel
Save