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; } 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 {