mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
fix: set belongs to many associations (#5759)
This commit is contained in:
parent
0e2b6343c2
commit
9166b7acf3
@ -133,6 +133,49 @@ describe('date-field', () => {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
it('should set default value if collection is middle table in belongs to many association', async () => {
|
||||
const middleTable = db.collection({
|
||||
name: 'test_middle',
|
||||
fields: [{ name: 'date1', type: 'datetimeTz', defaultToCurrentTime: true, allowNull: false }],
|
||||
});
|
||||
|
||||
const sourceTable = db.collection({
|
||||
name: 'test_source',
|
||||
fields: [
|
||||
{
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
name: 'target',
|
||||
target: 'test_target',
|
||||
type: 'belongsToMany',
|
||||
through: 'test_middle',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const targetTable = db.collection({
|
||||
name: 'test_target',
|
||||
fields: [
|
||||
{ name: 'name', type: 'string' },
|
||||
{ name: 'source', target: 'test_source', type: 'belongsToMany', through: 'test_middle' },
|
||||
],
|
||||
});
|
||||
|
||||
await db.sync();
|
||||
|
||||
const sourceInstance = await sourceTable.repository.create({ values: { name: 'source' } });
|
||||
const targetInstance = await targetTable.repository.create({ values: { name: 'target' } });
|
||||
|
||||
await sourceTable.repository.update({
|
||||
values: {
|
||||
target: [targetInstance.get('id')],
|
||||
},
|
||||
filter: { id: sourceInstance.get('id') },
|
||||
});
|
||||
});
|
||||
|
||||
it('should set default to current time', async () => {
|
||||
const c1 = db.collection({
|
||||
name: 'test11',
|
||||
|
@ -421,7 +421,7 @@ export async function updateMultipleAssociation(
|
||||
const createAccessor = association.accessors.create;
|
||||
|
||||
if (isUndefinedOrNull(value)) {
|
||||
await model[setAccessor](null, { transaction, context, individualHooks: true });
|
||||
await model[setAccessor](null, { transaction, context, individualHooks: true, validate: false });
|
||||
model.setDataValue(key, null);
|
||||
return;
|
||||
}
|
||||
@ -433,7 +433,7 @@ export async function updateMultipleAssociation(
|
||||
}
|
||||
|
||||
if (isStringOrNumber(value)) {
|
||||
await model[setAccessor](value, { transaction, context, individualHooks: true });
|
||||
await model[setAccessor](value, { transaction, context, individualHooks: true, validate: false });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -472,7 +472,7 @@ export async function updateMultipleAssociation(
|
||||
}
|
||||
|
||||
// associate targets in lists1
|
||||
await model[setAccessor](setItems, { transaction, context, individualHooks: true });
|
||||
await model[setAccessor](setItems, { transaction, context, individualHooks: true, validate: false });
|
||||
|
||||
const newItems = [];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user