我想找到一种方法来检索我所有的属性,而在我的数据库插入。
models.association.build(associationParams)
.save()
.then(function(assoAdded){
return next(assoAdded);
}).catch(function(err){
// # TODO : implement error Handler
return next(err);
});
I got this:
{
"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.
});