複数のテーブルから特定のユーザーデータが存在することを確認して、同時に呼び出すようにしたいのですが、私はBluebird Promise.Propを以下のように使用しています。 sequelize ORMを使用してデータにアクセスします。Sequelize findOneメソッドを使用してBluebird約束で同時呼び出しを行います。戻り値は未定義
Promise.props({
user: (()=>{
return User.findOne({
where: {username: req.user.username}
});
}),
comments: (()=>{
return comments.findOne({
where: {username: req.user.username}
});
})
}).then((result)=> {
console.log(result.user.name, result.comments.count);
});
また、ネストされた約束で試しましたが、成功しませんでした。 like
Promise.props({
user: (()=>{
return User.findOne({
where: {username: req.user.username}
}).then((user)=>{
console.log(user.name); // even here i am getting undefined
});
}),
comments: (()=>{
return comments.findOne({
where: {username: req.user.username}
});
})
}).then((result)=> {
console.log(result.user.name, result.comments.count);
});