我创建了两个表,一个是用户表,另一个是朋友表,其中包含用户之间的关系。
创建好友表是为了解决用户之间的多对多关系。
如何创建typeorm实体并检索下面表单中的数据?
{
"id": "1000014",
"name": "fu",
"address": aasd,
"createdTime": "2023-03-09T01:00:00.000Z",
"updatedTime": "2023-03-09T09:11:18.243Z",
"friends": [
{
"id": "5",
"name": "kaka",
"address": asdf,
"createdTime": "2023-03-09T01:00:00.000Z",
"updatedTime": "2023-03-09T09:11:18.243Z"
},
{
"id": "6",
"name": "lod",
"address": asdf,
"createdTime": "2023-03-09T01:00:00.000Z",
"updatedTime": "2023-03-09T09:11:18.243Z"
},
{
"id": "7",
"name": "asdf",
"address": asdf,
"createdTime": "2023-03-09T01:00:00.000Z",
"updatedTime": "2023-03-09T09:11:18.243Z"
},
{
"id": "8",
"name": "qwer",
"address": asdf,
"createdTime": "2023-03-09T01:00:00.000Z",
"updatedTime": "2023-03-09T09:11:18.243Z"
},
{
"id": "9",
"name": "qwer",
"address": dasfsdf,
"createdTime": "2023-03-09T01:00:00.000Z",
"updatedTime": "2023-03-09T09:11:18.243Z"
}
]
},
{
"id": "1000120",
"name": "asdvv",
"address": asdf,
"createdTime": "2023-03-08T15:00:00.000Z",
"updatedTime": "2023-03-09T09:11:18.243Z",
"friends": [
{
2条答案
按热度按时间iibxawm41#
假设您已经在数据库中创建了必要的表,您可以在TypeORM中为User和Friend表创建两个实体。
用户实体:
好友实体:
创建实体后,您可以使用TypeORM以所需格式检索数据,使用如下查询:
pxy2qtax2#
这可能行得通: