如何通过在sails.js查询参数选择填充水线协会 [英] How to selectively populate waterline associations via query param in sails.js

查看:438
本文介绍了如何通过在sails.js查询参数选择填充水线协会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认情况下,将帆时,它的相应API路线被击中填充模型中的所有关系。有谁知道,如果有可能触发这个功能?如果我有一个一对多的关联的工作,我可能不希望做的所有项目由于性能原因的列表,当填充的关联。但查看单个项目时,这将是很好完成的人口。

By default, sails will populate all relationships within a model when it's corresponding API route is hit. Does anyone know if it's possible to toggle this functionality? If I'm working with a one-to-many association, I may not want to populate the association when doing a listing of all items for performance reasons. But when viewing a single item, it would be nice to complete the population.

举例来说,假设一票可以有很多评论。我不在乎获取案件何时上市,但在​​查看具体的情况时很重要的意见。我参加了一个猜测它如何能发挥作用,但它失败:

For example, say one ticket can have many comments. I don't care about the comments when fetching a case listing but would be important when viewing a specific case. I took a guess at how it could function but it fails:

localhost:1337/tickets?populate=false

更新

我实现 balderdashy /帆#169​​5 内的上述功能。唯一的变化是,你有选择性地选择使用要填充的关联:

Update

I implemented the above functionality within balderdashy/sails#1695. The only change is that you selectively choose which associations to populate using:

localhost:1337/tickets?populate=[]          // Don't populate anything
localhost:1337/tickets?populate=[comments]  // Only populate comments

这将会覆盖无论是用于定义填充您的蓝图配置中。

This would override whatever is defined for populate within your blueprint config.

推荐答案

您只需要通过逗号来分隔assosiactions,就像这样:

You just need to separate your assosiactions via comma, just like this:

localhost:1337/tickets?populate=comments,owner&SOME_OTHER_PARAMS

这篇关于如何通过在sails.js查询参数选择填充水线协会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆