mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix(db): the string sourceKeyValue
in relation repository is being converted to a number (#6360)
This commit is contained in:
parent
8d40210948
commit
4b2b1da8ad
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { MockDatabase, mockDatabase } from '../../mock-database';
|
||||
|
||||
describe('relation repository', () => {
|
||||
let db: MockDatabase;
|
||||
beforeEach(() => {
|
||||
db = mockDatabase();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await db.clean({ drop: true });
|
||||
await db.close();
|
||||
});
|
||||
|
||||
it('should not convert string source id to number', async () => {
|
||||
db.collection({
|
||||
name: 'tags',
|
||||
fields: [{ type: 'string', name: 'name' }],
|
||||
});
|
||||
const User = db.collection({
|
||||
name: 'users',
|
||||
autoGenId: false,
|
||||
fields: [
|
||||
{ type: 'string', name: 'name' },
|
||||
{ type: 'hasMany', name: 'tags', sourceKey: 'name', target: 'tags', foreignKey: 'userId' },
|
||||
],
|
||||
});
|
||||
await db.sync();
|
||||
await User.repository.create({
|
||||
values: { name: '123', tags: [{ name: 'tag1' }] },
|
||||
});
|
||||
const repo = db.getRepository('users.tags', '123');
|
||||
await expect(repo.find()).resolves.not.toThrow();
|
||||
});
|
||||
});
|
@ -57,7 +57,8 @@ export abstract class RelationRepository {
|
||||
decodeMultiTargetKey(str: string) {
|
||||
try {
|
||||
const decoded = decodeURIComponent(str);
|
||||
return JSON.parse(decoded);
|
||||
const parsed = JSON.parse(decoded);
|
||||
return typeof parsed === 'object' && parsed !== null ? parsed : decoded;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user