sequelize / sequelize-typescript

Decorators and some other features for sequelize
MIT License
2.79k stars 282 forks source link

BaseModel Column order ? #1324

Open fortezhuo opened 2 years ago

fortezhuo commented 2 years ago

Issue

BaseModel.ts

import {
  CreatedAt,
  UpdatedAt,
  Model,
  Column,
  DeletedAt,
} from "sequelize-typescript"

export class BaseModel<T extends Model<T>> extends Model<T> {
  @CreatedAt
  _createdAt: Date

  @Column
  _createdBy: string

  @UpdatedAt
  _updatedAt: Date

  @Column
  _updatedBy: string

  @DeletedAt
  _deletedAt?: Date
}

And while we create User that extends BaseModel

class User extends BaseModel<User> {
  @Column(DataType.TEXT)
  firstName: string

  @Column(DataType.TEXT)
  lastName: string

  @Column(DataType.TEXT)
  fullName: string
}

Versions

Issue type

Actual behavior

The columns will be generated with order like this

id
_createdBy
_updatedBy
firstName
lastName
fullName
_createdAt
_updatedAt
_deletedAt

Expected behavior

How to create class User that order like

id
firstName
lastName
fullName
_createdBy
_updatedBy
_createdAt
_updatedAt
_deletedAt
Coinhexa commented 2 years ago

My question on top of this exact issue would be how do you change column order without changing your model

Oscaner commented 10 months ago

Any updates? I also encountered this problem.