且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在风帆水线 orm 中填充多个表

更新时间:2023-11-30 15:30:46

你提出了一个很好的问题.大量兴趣将嵌套填充功能放入帆中,实际上有数十个问题请求和 PR 等.

You ask a great question. There has been massive interest in getting nested populate feature into sails, literally tens of issue requests and PRs etc.

看看这里的一些历史:

[功能请求] 递归填充 #308 - 我参加聚会迟到了,您将在历史记录中看到的 2014 年 10 月 29 日提出请求.

[FEATURE REQUEST] Recursively populate #308 - i was late to the party, making the request on October 29th 2014 as you'll see in the history.

据我所知,大多数对话最终都集中在这里(在 Sails 用户请求该功能几年之后):

As far as I know, most conversations eventually converged here (after a couple of years of Sails users requesting the feature):

Deep populate #1052(问题仍然开放 撰写时 2016 年 1 月 14 日)

Deep populate #1052 (the issue remains open as of writing 14 Jan 2016)

从该问题的状态来看,我们目前还不清楚.这两个链接的历史确实表明其他人使用过的替代解决方法.

It is unclear from the state of that Issue where we are. The history of both links does suggest alternative workarounds others have used.

我的预感是不支持开箱即用的递归填充.

My hunch is that recursive populate is not supported out of the box.

我在将水线模型关联与 SailsJS 一起使用时所做的是使用像 async.js这样的包> - 使用类似瀑布的东西以编程方式显式填充子关系.您可以将执行此操作与覆盖默认的 toJSON() 结合起来您调用以将它们的关系(您以编程方式填充)添加到 JSON 响应的模型.您同样可以选择使用内置承诺来实现相同的目标.

What I did when using waterline model associations with SailsJS, was work with a package like async.js - use something like waterfall to explicitly populate the child relationships programmatically. You can combine doing this with overriding the default toJSON() of the models you invoke to add their relationships (which you have programmatically populated) to the JSON response. You could equally choose to use the built-in promises to achieve the same thing.

发现此(日期为 2014 年)SOF 问题,其中提供了更多信息.

Found this (dated, 2014) SOF Question which offers more information.

如果我错过了在最近的 Sails 或 Waterline 版本中添加的此功能,请在此纠正我 - 在任一项目的发行说明中都找不到任何说明支持此功能的内容.

Someone, do please correct me here if I have missed this feature addition in a recent Sails or Waterline version - couldn't find anything in the release notes for either project to say this was supported.