Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

319
Vistas
Sequelize: how can I override a Model's method from a defined Modal?

I am trying to achieve the following:

class User extends Model {
    // Specifically this override
    toJSON() {
        return { ...this.get(), id: undefined };
    }
}
User.init({
  // Attributes here
}, {sequelize});

The previous code uses the Modal class extension to override the toJSON method; however, I am working on a project where I defined most of my modals using sequelize.define like the following:

const User = sequelize.define('User', {
  // Attributes
});

Instead of refactoring all my models to extend the Modal class, is it possible to override my modals methods?

I tried using the getterMethods like so

getterMethods: {
    get: () => {
        return {...this.get(), id: undefined }
    }
}

Sadly I am using TypeScript that could not compile this code since Object is possibly 'undefined'. ts(2532). Thank you for your time.

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda