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

I'm not sure why this would happen as Im returning only the values of an instance in other locatio

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745586653a4634580.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信