fix: error

This commit is contained in:
chenos 2023-02-20 15:23:23 +08:00
parent 30a8678036
commit 479676d678
2 changed files with 20 additions and 2 deletions

View File

@ -60,15 +60,19 @@ describe('sort', function () {
const values = [
{
name: '1',
__index: '0',
children: [
{
name: '1-1',
__index: '0.children.0',
children: [
{
name: '1-1-1',
__index: '0.children.0.children.0',
children: [
{
name: '1-1-1-1',
__index: '0.children.0.children.0.children.0',
},
],
},
@ -78,15 +82,19 @@ describe('sort', function () {
},
{
name: '2',
__index: '1',
children: [
{
name: '2-1',
__index: '1.children.0',
children: [
{
name: '2-1-1',
__index: '1.children.0.children.0',
children: [
{
name: '2-1-1-1',
__index: '1.children.0.children.0.children.0',
},
],
},
@ -106,10 +114,17 @@ describe('sort', function () {
},
tree: true,
fields: ['id', 'name'],
appends: ['parent', 'children'],
sort: 'id',
});
console.log(
JSON.stringify(
instances.map((i) => i.toJSON()),
null,
2,
),
);
expect(instances.map((i) => i.toJSON())).toMatchObject(values);
const instance = await db.getRepository('categories').findOne({

View File

@ -134,7 +134,10 @@ export class Collection<
context: options.context,
});
if (children?.length > 0) {
instance.setDataValue('children', children);
instance.setDataValue(
'children',
children.map((r) => r.toJSON()),
);
}
}
});