mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 06:59:26 +08:00
fix: update table value without primary keys (#6124)
* fix: update table value without primary keys * fix: test * fix: test
This commit is contained in:
parent
b4eda8d04a
commit
f66a48abd0
@ -87,6 +87,40 @@ describe('update', () => {
|
|||||||
await db.sync();
|
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 () => {
|
it('should throw error when update data conflicted', async () => {
|
||||||
const t1 = await Tag.repository.create({
|
const t1 = await Tag.repository.create({
|
||||||
values: {
|
values: {
|
||||||
|
@ -22,6 +22,7 @@ import {
|
|||||||
FindOptions as SequelizeFindOptions,
|
FindOptions as SequelizeFindOptions,
|
||||||
UpdateOptions as SequelizeUpdateOptions,
|
UpdateOptions as SequelizeUpdateOptions,
|
||||||
Transactionable,
|
Transactionable,
|
||||||
|
Utils,
|
||||||
WhereOperators,
|
WhereOperators,
|
||||||
} from 'sequelize';
|
} from 'sequelize';
|
||||||
|
|
||||||
@ -420,6 +421,10 @@ export class Repository<TModelAttributes extends {} = any, TCreationAttributes e
|
|||||||
|
|
||||||
rows = eagerLoadingTree.root.instances;
|
rows = eagerLoadingTree.root.instances;
|
||||||
} else {
|
} else {
|
||||||
|
if (opts.where && model.primaryKeyAttributes.length === 0) {
|
||||||
|
opts.where = Utils.mapWhereFieldNames(opts.where, model);
|
||||||
|
}
|
||||||
|
|
||||||
rows = await model.findAll({
|
rows = await model.findAll({
|
||||||
...opts,
|
...opts,
|
||||||
transaction,
|
transaction,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user