【问题标题】:How to join/populate 3 tables with Bookshelf in Node.js如何在 Node.js 中使用 Bookshelf 加入/填充 3 个表
【发布时间】:2020-10-21 15:08:41
【问题描述】:

[这与已经提出的问题不同]

我有 3 个表格书,章节,段落。

与章节相关的书籍。(一对多)

与段落相关的章节(一对多)

如何查询Book并获取相关Chapter和Paragraph?寻找类似嵌套 withRelated 的东西

预期输出

[
  {
    "book1Info": "",
    "Chapters": [
      {
        "chaptor1Info": "",
        "Paragraphes": [
          {
            "page1": ""
          },
          {
            "page2": ""
          }
        ]
      },
      {}
    ]
  },
  {}
]

我已阅读文档并尝试 withRelated 没有成功

【问题讨论】:

    标签: node.js postgresql bookshelf.js


    【解决方案1】:

    我在 Bookshelf.js 文档上找不到它,但在 github 问题页面上找到了一些相关的东西,这有助于解决这个问题-

    您可以使用withRelated 并提供带有点的嵌套表。

    例如-

    withRelated: ['Books.Chapters']

    甚至

    withRelated: ['Books.Chapters.paragraphs']

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-14
      • 2018-12-13
      • 1970-01-01
      • 2017-10-27
      • 2019-10-03
      • 1970-01-01
      • 2017-10-02
      • 2021-03-14
      相关资源
      最近更新 更多