Merge branch 'next' into develop

This commit is contained in:
nocobase[bot] 2025-01-23 02:46:43 +00:00
commit bf756708a5
2 changed files with 39 additions and 0 deletions

View File

@ -87,6 +87,40 @@ describe('update', () => {
await db.sync();
});
it('should update collection that without primary key', async () => {
const collection = db.collection({
name: 'without_pk',
autoGenId: false,
timestamps: false,
fields: [{ type: 'string', name: 'nameWithUnderscore' }],
});
await collection.sync();
await collection.repository.create({
values: {
nameWithUnderscore: 'item1',
},
});
await collection.repository.update({
values: {
nameWithUnderscore: 'item2',
},
filter: {
nameWithUnderscore: 'item1',
},
});
const item = await collection.repository.findOne({
filter: {
nameWithUnderscore: 'item2',
},
});
expect(item).toBeDefined();
});
it('should throw error when update data conflicted', async () => {
const t1 = await Tag.repository.create({
values: {

View File

@ -22,6 +22,7 @@ import {
FindOptions as SequelizeFindOptions,
UpdateOptions as SequelizeUpdateOptions,
Transactionable,
Utils,
WhereOperators,
} from 'sequelize';
@ -420,6 +421,10 @@ export class Repository<TModelAttributes extends {} = any, TCreationAttributes e
rows = eagerLoadingTree.root.instances;
} else {
if (opts.where && model.primaryKeyAttributes.length === 0) {
opts.where = Utils.mapWhereFieldNames(opts.where, model);
}
rows = await model.findAll({
...opts,
transaction,