如何通过 publishAdd()-notification 获取添加的记录(不仅仅是 id)? [英] How to get added record (not just the id) through publishAdd()-notification?

查看:34
本文介绍了如何通过 publishAdd()-notification 获取添加的记录(不仅仅是 id)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个 Sails.js 模型都有方法 publishAdd().这会在新记录添加到关联模型时通知每个侦听器.

Each Sails.js model has the method publishAdd(). This notifies every listener, when a new record was added to a associated model.

此通知不包含新创建的记录.所以我必须从客户端开始另一个请求来获取新记录.

This notification does not contain the newly created record. So I have to start another request from the client side to get the new record.

是否有可能,Sails.js 发送带有通知的新记录,以便我可以减少我的请求数?

Is there a possibility, that Sails.js sends the new record with the notification, so I can reduce my request count?

我意识到接受的答案是这样的:https://gist.github.com/openscript/7016c5fd8c5053b5e3a3

I realized the accepted answer like that: https://gist.github.com/openscript/7016c5fd8c5053b5e3a3

推荐答案

使用默认的 publishAdd 方法无法获取此记录.但是,您可以覆盖该方法并在您的实现中执行子记录查找.

There's no way to get this record using the default publishAdd method. However, you can override that method and do the child record lookup in your implementation.

您可以通过向该模型类添加 publishAdd 方法,在每个模型的基础上覆盖 publishAdd,或者为所有 模型覆盖它通过将方法添加到 config/models.js 文件.

You can override publishAdd on a per-model basis by adding a publishAdd method to that model class, or override it for all models by adding the method to the config/models.js file.

我会先复制默认的publishAdd() 方法,然后根据需要进行调整.

I would start by copying the default publishAdd() method and then tweaking as necessary.

这篇关于如何通过 publishAdd()-notification 获取添加的记录(不仅仅是 id)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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