Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 10 additions & 2 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ class Resource extends BaseResource {

rawAttributes(): Record<string, ModelAttributeColumnOptions> {
// 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<string, ModelAttributeColumnOptions>;
}

Expand All @@ -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<BaseProperty> {
Expand Down