Reputation: 5451
I tried to send two models to a view with Sequelize but I don't know how to proceed.
My code below doesn't work.
Post.findAll().success( function(posts) {
Creation.findAll().success( function(creations) {
res.render('admin_index', {
creations: creations,
posts: posts
});
});
});
Anthony
Upvotes: 3
Views: 1622
Reputation: 5157
Actually you arent returning any posts in your callback and that's why posts is undefined.
So that you cant access it in yoru res.render context.
Check this part of your callback
Creation.findAll().success( function(creations) {
// The other stuff
});
Here you are only returning creations instead you should write a query that returns both creations and posts. Or do multiple queries in a callback chain something like these.
RandomQuery.findAll().success( function(creations,posts) {
// The other stuff
});
Or chain the callbacks inside each other
Creation.findAll().success( function(creations) {
Post.findAll().success(function(posts){
res.render('admin_index', {
creations: creations,
posts: posts
});
});
});
Upvotes: 3