fix: sequelize primary key field with multi filter target keys (#5556)

This commit is contained in:
ChengLei Shao 2024-10-31 17:38:07 +08:00 committed by GitHub
parent a985bc46a8
commit eec0f30d40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -189,10 +189,6 @@ export class Collection<
return this.model.primaryKeyAttribute; return this.model.primaryKeyAttribute;
} }
isMultiFilterTargetKey() {
return Array.isArray(this.filterTargetKey) && this.filterTargetKey.length > 1;
}
get name() { get name() {
return this.options.name; return this.options.name;
} }
@ -225,6 +221,10 @@ export class Collection<
} }
} }
isMultiFilterTargetKey() {
return Array.isArray(this.filterTargetKey) && this.filterTargetKey.length > 1;
}
tableName() { tableName() {
const { name, tableName } = this.options; const { name, tableName } = this.options;
const tName = tableName || name; 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.init(null, this.sequelizeModelOptions());
this.model.options.modelName = this.options.name; this.model.options.modelName = this.options.name;