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

182
Visualizações
How to get Associated model row count in Sequelize?

Hi I have a following code. From this I need a total rows count from the Comment Model. Can you please help? Thanks in Advance!

Post.hasMany(models.Comment, {
  as: 'postComment',
  foreignKey: 'postId',
});

Comment.belongsTo(models.Post, {
  foreignKey: 'postId',
  as: 'post',
});

        return Post.findAndCountAll({
            attributes: [['postId', 'id'], 'target_population', 'title', ['type', 'category'], 'stage', ['text_content', 'comment'], ['time_posted', 'engagement_timeframe'], ['closing_date', 'engagement_completion'], ['engagement_end', 'engagement_close'], ['non_constituent_view', 'non_constituents'], ['discussion_board_enabled', 'discussion_board'], 'attached_documents', 'description'],
            where: where,
            offset: offset,
            limit: limit,
            distinct: true,
            include: [
                {
                    model: Survey,
                    as: 'survey',
                    attributes: ['isOpen'],
                    where: {isOpen: "TRUE"},
                    required: false,
                    include: [
                        {
                            model: Question,
                            as: 'question',
                            include: [
                                {
                                    model: ProposedAnswer,
                                    as: 'choice',
                                    attributes: [['proposedAnswerId', 'id'], ['answer', 'value']],
                                    required: false,
                                }
                            ],
                            attributes: [['questionId', 'id'], ['question', 'title'], ['questionType', 'type']]
                        }
                    ]
                },
                {
                    model: User,
                    as: 'user',
                    attributes: ['first_name'],
                    where: {userId: {[Op.not]: null}},
                },
                {
                    model: Topic,
                    as: 'topic',
                    attributes: [['topicId', 'id'], ['name', 'value']],
                    through: {attributes: []},
                },
                {
                    model: Comment,
                    as: 'postComment',
                },
            ],
            order: [
                ['postId', 'DESC'],
            ]
        })
about 4 years ago · Juan Pablo Isaza
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