fix: SequelizeForeignKeyConstraintError: insert or update on table "actions_scopes" violates foreign key constraint "actions_scopes_collection_name_fkey"

This commit is contained in:
chenos 2021-01-23 11:17:36 +08:00
parent 1d8de0bc4e
commit f1c0503916
2 changed files with 18 additions and 6 deletions

View File

@ -73,6 +73,18 @@ const defaultValues = {
default: true,
},
],
scopes: [
{
title: '全部数据',
filter: {},
},
{
title: '用户自己的数据',
filter: {
"created_by_id.$currentUser": true,
},
},
],
};
export default async function (model: CollectionModel, options: any = {}) {

View File

@ -55,12 +55,12 @@ export class Permissions {
// const s = await model.createScope(scope, options);
// console.log(s.toJSON());
// }
try {
await Scope.bulkCreate(defaultScopes.map(scope => ({...scope, collection_name: model.get('name')})));
} catch (error) {
console.error(error);
throw error;
}
// try {
// await Scope.bulkCreate(defaultScopes.map(scope => ({...scope, collection_name: model.get('name')})));
// } catch (error) {
// console.error(error);
// throw error;
// }
});
database.getModel('users').addHook('afterCreate', async(model, options) => {