美文网首页程序员
RESTful 获取数据列表并包含关联数据

RESTful 获取数据列表并包含关联数据

作者: coolfireApy | 来源:发表于2017-10-31 15:26 被阅读71次
    • config/blueprints.js中的populate:填充开关

    /***************************************************************************
     *                                                                          *
     * Whether the blueprint controllers should populate model fetches with     *
     * data from other models which are linked by associations                  *
     * If you have a lot of data in one-to-many associations, leaving this on   *
     * may result in very heavy api calls                                       *
     ***************************************************************************/
    
    populate: false
    

    该参数控制blueprint controllers是否应该用其他关联model中的数据来填充model。如果在一对多的关联中有大量的数据,这将导致非常沉重的api调用,故默认为false,全局restful接口调用不填充。

    • config/route.js中的restful接口设置,populate:true可跳过全局不填充设置,单独接口调用可以用关联model数据填充

    /**
     * 店员获取接收的信息
     */
    'GET /msgToShop/getReceiveMessage': [
        {policy: 'isAuth'},//鉴权
        {policy: 'queryByUser'},//鉴权
        {blueprint: 'find', model: 'msgtoshop', populate: true}
    ]
    

    • 数据返回实例


      restful接口返回
    • 对应数据库msgtoshop表中数据

    数据库中数据
    • nodejs新手,如有不足请指出,代码HybWeb,欢迎点赞!

    相关文章

      网友评论

        本文标题:RESTful 获取数据列表并包含关联数据

        本文链接:https://www.haomeiwen.com/subject/jefppxtx.html