[英]#Sequelize while adding retrieve all attributes
我想找到一種在插入數據庫時檢索所有屬性的方法。
models.association.build(associationParams)
.save()
.then(function(assoAdded){
return next(assoAdded);
}).catch(function(err){
// # TODO : implement error Handler
return next(err);
});
我懂了 :
{
"idAssoParente": null,
"id": 420,
"name": "a",
"email": "aa@aa.aa",
"updated_at": "2015-07-29T17:12:47.000Z",
"created_at": "2015-07-29T17:12:47.000Z"
}
但是我想從我的數據庫返回我的所有字段,例如description , phone , city
,即使它們為空。 我應該在添加后獲取所有字段嗎?還是存在一種無需執行其他請求即可檢索我的字段的方法? 謝謝
簡而言之,是的,您將需要查詢數據庫以返回信息。 我剛開始使用Sequelize,但發現以下對我有用。
// if all the info you need is in your user
Users.build({req.body})
.save()
.then(function(newUser){
Users.find({where: {UserID: newUser.UserID}}).then(function(user){
//resolve your promise as you please.
});
// or if address info is in another model you can use eager loading.
Users.build({req.body})
.save()
.then(function(newUser){
Users.find({where: {UserID: newUser.UserID},
include: [{
model: address
}]
}).then(function(user){
//resolve your promise as you please.
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.