const like = Model.define('like', {
userId: {
type: sequelize.INTEGER,
allowNull: true,
},
topicId:{
type: sequelize.INTEGER,
allowNull: false
}
}, {
tableName: 'like',
timestamps: true,
updatedAt: false
})
like.hasMany(Topic,{foreignKey:'topicId',sourceKey:'topicId'})
这是我查询某个人的关注话题,并且从topic中获取话题的详细信息。比如title,描述等等。。。
await LikeModel.findAll({
include:{
model:TopicModel,
},
attributes:{exclude:['id','createdAt']}
}).then(res=>{
console.log(res)
ctx.body = res
})
得到的结果
[
{
"userId": "1",
"topicId": 1,
"topics": [
{
"topicId": 1,
"title": "1212",
"des": "2332"
}
]
},
{
"userId": "1",
"topicId": 2,
"topics": [
{
"topicId": 2,
"title": "1212",
"des": "2332"
}
]
}
]
userId: {
type: sequelize.INTEGER,
allowNull: true,
},
topicId:{
type: sequelize.INTEGER,
allowNull: false
}
}, {
tableName: 'like',
timestamps: true,
updatedAt: false
})
like.hasMany(Topic,{foreignKey:'topicId',sourceKey:'topicId'})
这是我查询某个人的关注话题,并且从topic中获取话题的详细信息。比如title,描述等等。。。
await LikeModel.findAll({
include:{
model:TopicModel,
},
attributes:{exclude:['id','createdAt']}
}).then(res=>{
console.log(res)
ctx.body = res
})
得到的结果
[
{
"userId": "1",
"topicId": 1,
"topics": [
{
"topicId": 1,
"title": "1212",
"des": "2332"
}
]
},
{
"userId": "1",
"topicId": 2,
"topics": [
{
"topicId": 2,
"title": "1212",
"des": "2332"
}
]
}
]