[英]How to get data from one table and use it in another in sequelize(postgres)
[英]Including attribute from another table as one field with Sequelize
我正在使用Sequelize包含其他模型對事件的重要性。 每個事件都有重要性值,重要性在不同的表中定義。 我需要能夠從后端詢問事件,以便它將重要性值作為一個屬性提供給我。 目前,它給了我包含屬性的對象。
我嘗試過包括對事件的模型重要性。
Event.findAll({
attributes: {
exclude: ['importance_id']
},
include: [{
model: Importance,
attributes: ['value'],
}]
})
這就是我得到的:
{
"id": 1,
"name": "name 1",
"Importance": {
"value": 1
}
}
它應該是這樣的:
{
"id": 1,
"name": "name 1",
"value": 1
}
我在findAll對象中添加了raw:true,現在我得到這樣的數據:
{
"id": 1,
"name": "name 1",
"Importance.value": 1
}
這不完全是我想要的,但是可以解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.