我将 Dynamodb 与 nodejs 一起用于我的预订系统。和Dynamoose作为 ORM。我有两张桌子,即Table和Reservation。为了在它们之间创建关系,我在Reservation中添加了tableId属性,该属性是 Model 类型(Table 类型),如 dyanmoose docs中所述。使用document.populate我可以通过来自Reservation表的tableId属性获取表数据。但是我怎样才能检索一个表的所有预订?(Reservation 和 Table 有一对多的关系)?
这些是我的模型: 表模型:
const tableSchema = new Schema ({
tableId: {
type: String,
required: true,
unique: true,
hashKey: true
},
name: {
type: String,
default: null
},
});
*Reservation Model:*
const reservationSchema = new Schema ({
id: {
type: Number,
required: true,
unique: true,
hashKey: true
},
tableId: table, \\as per doc attribute of Table (Model) type
date: {
type: String
}
});
这就是我从预订模型中检索表数据的方式
reservationModel.scan().exec()
.then(posts => {
return posts.populate({
path: 'tableId',
model: 'Space'
});
})
.then(populatedPosts => {
console.log('pp',populatedPosts);
return {
allData: {
message: "Executedddd succesfully",
data: populatedPosts
}
}
})
请任何人帮助从表中检索所有预订数据?