Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!