首页 > 解决方案 > Sequelize 原始查询未正确打印

问题描述

我正在尝试在 sequelize 中编写查询,但查询不起作用下面是我在 sequelize 中编写的查询

var homePosts = db.postbox.findAll({
        where: {
            user_id: {
                $or: {
                    $eq: id,
                    $in: [id]
                }
            }
        },
        attributes: ["user_posts_id"],
        limit: 5
    });
    return homePosts;

Node js打印结果查询

Executing (default): SELECT `user_posts_id` FROM `user_posts_boxes` AS `user_posts_boxes` WHERE `user_posts_boxes`.`user_id` = '[object Object]' LIMIT 5;
[]

它打印对象而不是变量值并打印后续准备的实际查询。

我的实际原始查询如下,我实际上想将其转换为续集

SELECT `user_posts_id` FROM `user_posts_boxes` AS `user_posts_boxes` WHERE ( `user_posts_boxes`.`user_id` = '5' OR `user_posts_boxes`.`user_id` IN (select following_id from friend WHERE friend.follower_id = user_posts_boxes.user_id and friend.status='A' and friend.following_id=5)) LIMIT 5

标签: node.jssequelize.js

解决方案


我对 Sequelize 5 有同样的问题。使用基于符号的运算符应该没问题https://github.com/sequelize/sequelize/issues/8417


推荐阅读