admin管理员组

文章数量:1022944

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

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

本文标签: javascriptSequelize Calling get(plain true )) returns get is not a functionStack Overflow