Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
Relationship from relationship Model Query Sequelize

I have a question as to how I can recover a relationship within another relationship using SEQUELIZE in NODEJS.

Example, in Laravel PHP I can do something like this:

Model::with(['character.genetic'])->get()

That way it will bring the relationship of "Character" and the relationship that "Character has with Genetic", however, how can I do that in NODE?

Below is an example of my code in NodeJS:

let data = await PlayerCharacter.findAll({
        include: ['character.genetic'], ///dont works
        where: {
          playerId: req.playerId,
        },
        order: [
          ['levelId', 'desc']
        ]
      });

My class Main

import Sequelize from 'sequelize';
import database from '../database';

const PlayerCharacter = database.define('player_characters', {
    .....
    characterId: {
        type: Sequelize.BIGINT,
        allowNull: false,
    },
    .....
});

/**
 * Relationships
 */

PlayerCharacter.belongsTo(Character, {
    foreignKey: 'characterId',
    as: 'character',
});

export default PlayerCharacter;

My Class Character

import Sequelize from 'sequelize';
import database from '../database';

const Character = database.define('characters', {
    ...
    geneticId: {
        type: Sequelize.INTEGER,
        allowNull: false,
    },
   ....
}, {
    timestamps: false,
});

/**
 * Relationships
 */

Character.hasOne(CharacterGenetic, {
    foreignKey: 'geneticId',
    as: 'genetic',
});

export default Character;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should use nested include option like this:

let data = await PlayerCharacter.findAll({
        include: [{
          model: Character,
          as: 'character',
          include: [{
            model: CharacterGenetic,
            as: 'genetic'
          }  
          ]
        }
        ],
        where: {
          playerId: req.playerId,
        },
        order: [
          ['levelId', 'desc']
        ]
      });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda