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

142
Views
Dos claves foráneas una tabla en sequalize

Tengo la tabla de ofertas de 2 filas exit_customs y destination_customs. Esta fila 2 tiene una identificación de tabla de mi Aduana. Mi problema es cómo dos (exit_customs y destination_customs) una tabla de clave externa (Aduana)?

Aquí está mi función de consulta de lista

 router.post('/api/logistic/offers/get-offers', async (req, res) => { const {limit, page, sortColumn, sortType, search} = req.body; const total = await Offers.findAll(); const offersList = await Offers.findAll({ limit: limit, offset: (page - 1) * limit, order: [ [sortColumn, sortType] ], where: { [Op.or]:[ { offers_no: { [Op.substring]: [ search ] } }, { agreement_date: { [Op.substring]: [ search ] } }, { routes: { [Op.substring]: [ search ] } }, { type_of_the_transport: { [Op.substring]: [ search ] } }, ] } }); res.json({ total: total.length, data: offersList }); })
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

esta solución conecta los dos datos en la primera tabla con la identificación en la otra tabla como desee. Espero eso ayude

 Offers.belongsTo(Customs, {as: 'Exit_customs', foreignKey: 'exit_customs'}); Offers.belongsTo(Customs, {as: 'Destination_customs', foreignKey: 'destination_customs'}); router.post('/api/logistic/offers/get-offers', async (req, res) => { const {limit, page, sortColumn, sortType, search} = req.body; const total = await Offers.findAll(); const offersList = await Offers.findAll({ limit: limit, offset: (page - 1) * limit, order: [ [sortColumn, sortType] ], where: { [Op.or]: [ { offers_no: { [Op.substring]: [ search ] } }, { agreement_date: { [Op.substring]: [ search ] } }, { routes: { [Op.substring]: [ search ] } }, { type_of_the_transport: { [Op.substring]: [ search ] } }, ] }, include: [{ model: Customs, as: 'Exit_customs' }, { model: Customs, as: 'Destination_customs' }] }); res.json({ total: total.length, data: offersList }); })
about 4 years ago · Santiago Trujillo Report

0

Puede proporcionar una clave externa usando la palabra clave "as" , agregue el código a continuación en su archivo de modelos de ofertas

 static associate(models) { models.Offers.belongsTo(models.Customs, { foreignKey: "exit_customs", as: "exitCustomsDetails", }); models.Offers.belongsTo(models.Customs, { foreignKey: "destination_customs", as: "destinationCustomsDetails", }); }
about 4 years ago · Santiago Trujillo 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!