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

245
Vistas
¿Cómo invocar un Prototipo desde dentro de un Hook en un Modelo?

Uso Sequelize y en mi modelo de usuario tengo un gancho y un prototipo (ver más abajo). En la segunda línea del gancho, trato de hacer referencia al prototipo. Pero esto no funciona. Vuelve

this.getAllUsersInclMemberno es una función

¿Cómo puedo invocar el prototipo desde el interior del gancho?

 module.exports = (sequelize) => { User.afterUpdate(async (options) => { // here I try to call upon the prototype for the instance let users = await this.getAllUsersInclMembers(); await Promise.all( await users.forEach(async (user) => { // here we reference to a prototype in another model user.syncToDb(); }) ); }); User.prototype.getAllUsersInclMembers = function { return sequelize.models.Product.findAll({ where: { user_id: this.getDataValue("id") }, }); }; };

Actualización: actualicé el gancho al código a continuación, pero aún con el mismo resultado:

 User.afterUpdate(async function (user, options) { // here I try to call upon the prototype for the instance let users = await this.getAllUsersInclMembers(); await Promise.all( await users.forEach(async (user) => { // here we reference to a prototype in another model user.syncToDb(); }) ); });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

lo he resuelto:

 User.addHook("afterUpdate", async function (instance, options) { let users = await instance.getAllUsersInclMembers(); await Promise.all( await users.forEach(async (user) => { // here we reference to a prototype in another model user.syncToDb(); }) ); });
about 4 years ago · Juan Pablo Isaza Denunciar
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