我在如何从端点之一取回数据方面遇到了一些问题 - 特别是使用 Marshmallow 和 SQLAlchemy。
我在鸡尾酒和配料之间有多对多的关系,但我在关系表 ings_in_cocktail 上也有不仅仅是外键的更多数据,例如ounces.When I GET /cocktails/,它返回如下内容:
{
"cocktails": [
{
"glass": "rocks",
"ingredients": [
{
"ingredient": {
"ing_type": "liquor",
"id": 1,
"name": "gin"
},
"ounces": 20
}
],
"finish": "stirred",
"id": 1,
"name": "gin and tonic"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想做的是将财产的传播ounces与ingredient字典结合起来。
我希望数据如下所示:
{
"cocktails": [
{
"glass": "rocks",
"ingredients": [
{
"ing_type": "liquor",
"id": 1,
"name": "gin",
"ounces": 20
}
],
"finish": "stirred",
"id": 1,
"name": "gin and …Run Code Online (Sandbox Code Playgroud)