javascript - 我应该如何嵌入具有多对多关系的 2 个模型?
问题描述
我有两个具有多对多关系的模型:
- 博客
- 标签
所以每个博客都有一个tags
属性,每个标签都有一个blogs
属性。我还有两个 API 端点:/blogs 和 /tags
我的问题是,如果我在序列化程序中包含并嵌入模型,我会收到带有错误消息“超出最大调用堆栈大小”的循环引用
我想看到这样的东西:
GET /api/blogs
[
{
"id": "1",
"title": "Some title",
"author": "Author 0",
"tags": [
{
"id": "1",
"name": "Tag 0"
},
{
"id": "2",
"name": "Tag 1"
}
]
}
]
GET /api/tags
[
{
"id": "1",
"name": "Tag 0",
"blogs": [
{
"id": "1",
"title": "Some title",
"author": "Author 0"
}
]
},
{
"id": "2",
"name": "Tag 1",
"blogs": [
{
"id": "1",
"title": "Some title",
"author": "Author 0"
}
]
}
]
解决方案
推荐阅读
- delphi - Delphi 中的清洁使用子句
- spring-webflux - Spring Webflux - 服务器/客户端线程利用率
- c - 在 C 中打印字符串中的字符时出现分段错误
- c++ - 需要一个正态分布的随机数生成器
- c# - 如果第一个链接不可用,我如何加载另一个链接?在c#中
- php - 我面临一个无法修复的错误 - 商店网站中的 Buy_Item
- php - 如何在一个 SQL 表中创建无限类别子项
- google-chrome - 使用 Chrome 扩展删除所有 CSP 标头以允许 iframe
- asp.net - ASP.net 找不到资源。重定向到不应重定向到的页面
- powershell - 如何使用需要从命令提示符/批处理文件中引用的参数调用 PowerShell Start-Process 命令?