我有两个具有多对多关系的模型:
- 博客
- 标签
所以每个博客都有一个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"
}
]
}
]