From 7029fed0ff02226cdce203a6d5f44c5f4dbcbee8 Mon Sep 17 00:00:00 2001 From: Sascha Depold Date: Thu, 30 Nov 2023 10:53:00 +0100 Subject: [PATCH 1/2] Add support for Sequelize v7 --- src/resource.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/resource.ts b/src/resource.ts index 5a74f38..991ef98 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -37,9 +37,11 @@ class Resource extends BaseResource { rawAttributes(): Record { // different sequelize versions stores attributes in different places + // .modelDefinition.attributes => sequelize ^7.0.0 // .rawAttributes => sequelize ^5.0.0 // .attributes => sequelize ^4.0.0 return ((this.SequelizeModel as any).attributes + || ((this.SequelizeModel as any).modelDefinition?.attributes && Object.fromEntries((this.SequelizeModel as any).modelDefinition?.attributes)) || (this.SequelizeModel as any).rawAttributes) as Record; } @@ -54,11 +56,17 @@ class Resource extends BaseResource { } name(): string { - return this.SequelizeModel.tableName; + // different sequelize versions stores attributes in different places + // .modelDefinition.table => sequelize ^7.0.0 + // .tableName => sequelize ^4.0.0 + return ( + (this.SequelizeModel as any).modelDefinition?.table?.tableName + || this.SequelizeModel.tableName + ); } id(): string { - return this.SequelizeModel.tableName; + return this.name(); } properties(): Array { From 6951b3a5c85e1f14e709c3acf320869a5e7d2cee Mon Sep 17 00:00:00 2001 From: Sascha Depold Date: Thu, 30 Nov 2023 13:19:59 +0100 Subject: [PATCH 2/2] Add v7 support for properties --- src/property.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/property.ts b/src/property.ts index 7d94a89..6f5e324 100644 --- a/src/property.ts +++ b/src/property.ts @@ -73,6 +73,11 @@ class Property extends BaseProperty { if (this.sequelizePath.references === 'string') { return this.sequelizePath.references as string; } if (this.sequelizePath.references && typeof this.sequelizePath.references !== 'string') { + // Sequelize v7 + if ((this.sequelizePath.references as any).table?.tableName) { + return (this.sequelizePath.references as any).table?.tableName as string; + } + // Sequelize v4+ if (this.sequelizePath.references.model && typeof this.sequelizePath.references.model !== 'string') { return (this.sequelizePath.references?.model as any)?.tableName as string; }