From eec0f30d40f5047f30f80bb8df801318eca04595 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Thu, 31 Oct 2024 17:38:07 +0800 Subject: [PATCH] fix: sequelize primary key field with multi filter target keys (#5556) --- packages/core/database/src/collection.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/core/database/src/collection.ts b/packages/core/database/src/collection.ts index f05eb39529..31866cf1a8 100644 --- a/packages/core/database/src/collection.ts +++ b/packages/core/database/src/collection.ts @@ -189,10 +189,6 @@ export class Collection< return this.model.primaryKeyAttribute; } - isMultiFilterTargetKey() { - return Array.isArray(this.filterTargetKey) && this.filterTargetKey.length > 1; - } - get name() { return this.options.name; } @@ -225,6 +221,10 @@ export class Collection< } } + isMultiFilterTargetKey() { + return Array.isArray(this.filterTargetKey) && this.filterTargetKey.length > 1; + } + tableName() { const { name, tableName } = this.options; const tName = tableName || name; @@ -313,6 +313,20 @@ export class Collection< }, }); + Object.defineProperty(this.model, 'primaryKeyField', { + get: function () { + if (this.primaryKeyAttribute) { + return this.rawAttributes[this.primaryKeyAttribute].field || this.primaryKeyAttribute; + } + + return null; + }.bind(this.model), + + set(val) { + this._primaryKeyField = val; + }, + }); + this.model.init(null, this.sequelizeModelOptions()); this.model.options.modelName = this.options.name;