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

169
Views
Secuela "objeto" no tiene función de incremento

Estoy usando generar tablas de secuelas a partir de modelos generados por Django con secuencialización automática en mi proyecto. Hasta ahora, todo bien. Escribí el código para actualizar el rango si vuelvo a ver una URL.

 const findLink = async (link) => Link.findOne({ where: { url: link, }, raw: true, }); // eslint-disable-next-line no-use-before-define const insertEvent = async (link, tweetText) => { // Sync Database table before reading await sequelize.sync(); findLink(link).then((url) => { if (url) { url.increment("rank", {by: 1}).then(()=>{ Event.create({ url_id: url.id, tweet_text: tweetText, created_at: new Date(), updated_at: new Date(), }) }); } else { Link.create({ url: link, rank: 0, created_at: new Date(), updated_at: new Date(), }).then((newLink) => { Event.create({ url_id: newLink.id, tweet_text: tweetText, created_at: new Date(), updated_at: new Date(), }); }); } }); };

Pero el problema es que cuando ejecuta url.increment("rank", {by: 1}) dice que url no tiene función increment .

Pero de acuerdo con la documentación, aquí se indica claramente. Por favor, hágamelo saber si estoy haciendo algo mal? He buscado en internet pero no he podido encontrar nada relativo. Puedo actualizar el valor con una búsqueda duplicada, pero estoy buscando una forma de actualizar el objeto ya encontrado en lugar de buscarlo nuevamente.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Estás usando consultas sin formato

 const findLink = async (link) => Link.findOne({ where: { url: link, }, raw: true, });

No devuelve una instancia del modelo.

Ver https://sequelize.org/master/manual/raw-queries.html

Editar:

De forma predeterminada, la función devolverá dos argumentos: una matriz de resultados y un objeto que contiene metadatos (como la cantidad de filas afectadas, etc.).

Una segunda opción es el modelo. Si pasa un modelo, los datos devueltos serán instancias de ese modelo.

 // Callee is the model definition. This allows you to easily map a query to a predefined model const projects = await sequelize.query('SELECT * FROM projects', { model: Projects, mapToModel: true // pass true here if you have any mapped fields }); // Each element of `projects` is now an instance of Project

Entonces, la opción mapToModel también podría funcionar

about 4 years ago · Juan Pablo Isaza Report
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!