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

314
Views
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 answers
Answer question

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 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!