From d3b157075e7d47ae99433d3cfb21724c81013008 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 29 Jun 2022 23:20:00 +0800 Subject: [PATCH] fix(database): constraints default to false (#550) * fix(database): constraints default to false * test(plugin-workflow): skip schedule cases Co-authored-by: mytharcher --- packages/core/database/src/fields/belongs-to-field.ts | 1 + packages/core/database/src/fields/belongs-to-many-field.ts | 1 + packages/core/database/src/fields/has-many-field.ts | 7 ++++--- packages/core/database/src/fields/has-one-field.ts | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core/database/src/fields/belongs-to-field.ts b/packages/core/database/src/fields/belongs-to-field.ts index 273a52351..bf3432125 100644 --- a/packages/core/database/src/fields/belongs-to-field.ts +++ b/packages/core/database/src/fields/belongs-to-field.ts @@ -28,6 +28,7 @@ export class BelongsToField extends RelationField { // define relation on sequelize model const association = collection.model.belongsTo(Target, { as: this.name, + constraints: false, ...omit(this.options, ['name', 'type', 'target']), }); diff --git a/packages/core/database/src/fields/belongs-to-many-field.ts b/packages/core/database/src/fields/belongs-to-many-field.ts index 5ae69d521..c2315217a 100644 --- a/packages/core/database/src/fields/belongs-to-many-field.ts +++ b/packages/core/database/src/fields/belongs-to-many-field.ts @@ -37,6 +37,7 @@ export class BelongsToManyField extends RelationField { } const association = collection.model.belongsToMany(Target, { + constraints: false, ...omit(this.options, ['name', 'type', 'target']), as: this.name, through: Through.model, diff --git a/packages/core/database/src/fields/has-many-field.ts b/packages/core/database/src/fields/has-many-field.ts index eddc624b4..d3f87ad13 100644 --- a/packages/core/database/src/fields/has-many-field.ts +++ b/packages/core/database/src/fields/has-many-field.ts @@ -5,10 +5,10 @@ import { ForeignKeyOptions, HasManyOptions, HasManyOptions as SequelizeHasManyOptions, - Utils, + Utils } from 'sequelize'; -import { BaseRelationFieldOptions, MultipleRelationFieldOptions, RelationField } from './relation-field'; +import { MultipleRelationFieldOptions, RelationField } from './relation-field'; export interface HasManyFieldOptions extends HasManyOptions { /** @@ -93,9 +93,10 @@ export class HasManyField extends RelationField { } const association = collection.model.hasMany(Target, { + constraints: false, + ...omit(this.options, ['name', 'type', 'target']), as: this.name, foreignKey: this.foreignKey, - ...omit(this.options, ['name', 'type', 'target']), }); // inverse relation diff --git a/packages/core/database/src/fields/has-one-field.ts b/packages/core/database/src/fields/has-one-field.ts index 0c40b60a4..ab3dbb958 100644 --- a/packages/core/database/src/fields/has-one-field.ts +++ b/packages/core/database/src/fields/has-one-field.ts @@ -92,9 +92,10 @@ export class HasOneField extends RelationField { return false; } const association = collection.model.hasOne(Target, { + constraints: false, + ...omit(this.options, ['name', 'type', 'target']), as: this.name, foreignKey: this.foreignKey, - ...omit(this.options, ['name', 'type', 'target']), }); // 建立关系之后从 pending 列表中删除 database.removePendingField(this);