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

196
Views
relación muchos a muchos knex js

Estoy tratando de obtener datos de la base de datos de esta manera: quiero todas las plantillas y esas plantillas tienen una variedad de categorías, así que

 templateArray = [ template1 = { name:string, ..., categories: array} template2 = { name:string, ..., categories: array} ]

el método que estoy usando actualmente

 const findAll = async () => { let template = await getKnex()(tables.template).select(); template.forEach(async (value) => { const categories = await getKnex()(tables.template) .select() .where(`${tables.template}.templateId`, value.templateId) .join( tables.template_category, `${tables.template}.templateId`, '=', `${tables.template_category}.template_id`, ) .join( tables.category, `${tables.category}.catId`, '=', `${tables.template_category}.cat_Id`, ); value.categories = categories; }); return template; };

actualmente estoy haciendo esto pero el objeto no parece alterarse.

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

0

No estás esperando a que las promesas se resuelvan. Deberías hacer:

 await Promise.all(template.map(yourFunction))

en vez de

 template.forEach(yourFunction)
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!