From 2ceda70a97954ef69076ae4e61267b700de5e749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 20 Mar 2021 15:51:34 -0400 Subject: [PATCH] fix: preserve order when changing parent --- src/categories/update.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/categories/update.js b/src/categories/update.js index 438e833639..cdca138635 100644 --- a/src/categories/update.js +++ b/src/categories/update.js @@ -69,10 +69,11 @@ module.exports = function (Categories) { if (childrenCids.includes(newParent)) { throw new Error('[[error:cant-set-child-as-parent]]'); } - const oldParent = await Categories.getCategoryField(cid, 'parentCid'); + const categoryData = await Categories.getCategoryFields(cid, ['parentCid', 'order']); + const oldParent = categoryData.parentCid; await Promise.all([ db.sortedSetRemove(`cid:${oldParent}:children`, cid), - db.sortedSetAdd(`cid:${newParent}:children`, cid, cid), + db.sortedSetAdd(`cid:${newParent}:children`, categoryData.order, cid), db.setObjectField(`category:${cid}`, 'parentCid', newParent), ]);