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

481
Visualizações
Nodejs Sequelize Attributes Get data inside an object

I have a postgres database which look like this :

enter image description here

I want to query those data and return only some of it. Below is the function that I wrote.

citizenController.js

exports.getAllCitizen = async (req, res) => {
  const { page, size } = req.query;
  //Check if theres a NIK filter
  const nik = req.query.nik;
  const condition = nik ? { nik: { [Op.iLike]: `%${nik}%` } } : null;

  //Pagination
  const { limit, offset } = getPagination(page, size);

  try {
    const response = await Penduduk.findAndCountAll({
      where: condition,
      attributes: ["id", "nik", "profil_penduduk"],
      limit,
      offset,
    });
    const data = getPagingData(response, page, limit);

    return res.status(200).send(data);
  } catch (err) {
    console.log(err);
  }
};

Here is the response from function above :

enter image description here

The problem is, I don't want to return all of the profil_penduduk object data, I just want to get the nama , alamat, and status_warga from it.

enter image description here

How can I achieve that ? I tried to do like :

attributes: ["id", "nik", "profil_penduduk.nama","profil_penduduk.alamat","profil_penduduk.status_warga"]

But it didn't work.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

1

Best way to get the details of reference table to use include as

const response = await Penduduk.findAndCountAll({
      where: condition,
      attributes: ["id", "nik"],
      include: [
        {
          model: profil_penduduk, // name of reference table
          attributes: ['nama' , 'alamat', 'status_warga'],
        }
      ],
      limit,
      offset,
    });
    ```
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