When I run any find function with sequelize, I expect to get an object of the data I am trying to get, instead, I get a bunch of extra data back.This is what I get when I print the result of what sequelize gave me
This is the code i run:
getAllHubsByUser: function(userId, callback){
db.User.findByPk(userId)
.then(function(user) {
user.getSubscriptions()
.then(function(hubs){
dataValuesHubs = []
for (hub in hubs) {
dataValuesMembers.push(hub.dataValues)
}
callback(dataValuesHubs, null)
})
.catch(function(error){
callback(null, error)
})
})
.catch(function(error) {
callback(null, error)
})
},
I have a many to many relation between a table called Hubs and Users, many users can be subscribed to many hubs. The relations looks like this:
User.belongsToMany(Hub, {as: "Subscriptions", through: 'hubSubscriptions', foreignKey: 'userId'})
Hub.belongsToMany(User, {as: "Subscribers", through: 'hubSubscriptions', foreignKey: 'hubId'})
Since sequelize don't return a object, i get an error when u run user.getSubscriptions(): "Unhandled rejection TypeError: Cannot read property 'findAll' of undefined"
How can i make it so sequelize sends back a object?