In Sequelize >=1.7 we can use promises
Can you explain for me how can i get values from each user in this code:
var User = sequelize.define(\"user\", {
The Bluebird way are the collection helper functions.
If you want to create them in parallel, use map:
User.sync({ force: true })
.then(function() {
return Promise.map( ['John', 'Jane', 'Pete'], function(name) {
return User.create({ username: name });
})
}).spread(function(john, jane, pete) {
console.log("we just created 3 users :)")
console.log("this is john:")
console.log(john.values)
console.log("this is jane:")
console.log(jane.values)
console.log("this is pete:")
console.log(pete.values)
})
If you need to create them consecutively, just change it to mapSeries (3.0+).
If the array doesn't need to be dynamic, and you simply want to pass a shared value through the promise chain like in your example, have a look at How do I access previous promise results in a .then() chain?.