最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sequelize: Calling .get({plain: true })) returns .get is not a function - Stack Overflow

programmeradmin1浏览0评论

I'm not sure why this would happen as Im returning only the values of an instance in other locations just fine. See anything wrong with my code?

app.get('/profile', checkAuth, function(req, res) {
    var useObj = req.user;
    var guilds = req.user.guilds;
    User.findAll({
        where: { userid: useObj.id },
        include: [{
            model: Guild
        }]
    }).then(function(group) {
        console.log(group.get({
            plain: true
        }))
    })  
});

I'm not sure why this would happen as Im returning only the values of an instance in other locations just fine. See anything wrong with my code?

app.get('/profile', checkAuth, function(req, res) {
    var useObj = req.user;
    var guilds = req.user.guilds;
    User.findAll({
        where: { userid: useObj.id },
        include: [{
            model: Guild
        }]
    }).then(function(group) {
        console.log(group.get({
            plain: true
        }))
    })  
});
Share Improve this question asked Sep 22, 2016 at 4:54 Mr. BigglesWorthMr. BigglesWorth 1,5403 gold badges19 silver badges33 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

The problem is you're trying to call get function of array, not instance, so, findAll() always returns an array of instances. Use findOne() instead or loop result

发布评论

评论列表(0)

  1. 暂无评论