sequelize 联合查询
我用sequelize 联合查询
db.user.hasMany(db.bbsuser,{foreignKey:'userId'});
db.bbsuser.belongsTo(db.user);
db.user.findAll({include:[db.bbsuser]});
得到结果格式以下:
{
"id": 9,
"username": "CallMeSoul",
"truename": "陈译彬a",
"phone": "18825111542",
"eamil": "",
"sex": 9,
"avatar": "http://wx.qlogo.cn/mmopen/LMZxJ2ofzuHgXWBvfrLfRrCibZ5I14KYWHlfA7AQicVOWZPWJl1K0icXM6AKZCiaY0pUyyoIHfDqf6ppXdpRLJSaLiacsbfhpdoPp/0",
"token": "",
"balance": 0,
"integral": 201,
"state": 9,
"country": "中国",
"province": "广东",
"city": "中山",
"openid": "oFMa7wNAA9zBgboSZm0dm9AdweLE999",
"createtime": null,
"udpatetime": null,
"bbsusers": [
{
"id": 22,
"userId": 9,
"bbsId": 3,
"isAdmin": 0,
"createTime": "2017-01-12T14:49:52.000Z"
}
]
}
但我想查出bbsId=3,的所有结果要怎么添加where语句呢?
我试过以下都不行:
db.user.findAll({where:{bbsId:4},include:[db.bbsuser]});
db.user.findAll({include:[db.bbsuser],{where:{bbsId:4}});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)