Querying from models with HasManyThrough relations - strongloop api

佐手、 提交于 2019-12-06 16:37:36

First create a hasMany relation between game and game_info model

//Now inside remote_method.
Category.mature = function(id, callback) {
    var app = this.app;
    var Game = app.models.game;
    Category.findById(id, {}, function(err, category) {
        if (err) return callback(err);
        //Now call the Game find method
        Game.find({
            "where": {
                categoryId: id,
                mature: true
            },
            include:'game_info'
        }, function(err, gameArr) {
            if (err) return callback(err);
            gameArr.forEach(function(gameObj, index){
                gameObj.categoryName = category.category_name;

            });
            callback(null, gameArr);
        });
    });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!