2016-06-30 3 views
0

モデルの結果をsails js blueprintの関連プロパティからソートすることはできますか?帆Js - 青写真と関連値でソート

例えば:

// Profile: 
module.exports = { 
    attributes: { 
     firstName: { type: 'string', required: true }, 
     lastName: { type: 'string', required: true }, 
     user: { model: 'user', required: true } 
    } 
}; 
// User: 
module.exports = { 
    attributes: { 
     email: { type: 'string', required: true } 
    } 
}; 

次にような何か:? /API /プロファイルを読み込む=ユーザー&ソート= user.email + DESC

答えて

1

いいえ、これは帆の青写真では不可能です。

あなたはそれを行うためにあなたのProfileControllerに新しいアクションを作成する必要があります。

findByEmailDesc: function (req, res) { 
    Profile 
    .find() 
    .populate('user') 
    .exec(function (err, profiles) { 
     if (err) return res.serverError(err); 

     return res.ok(_.sortBy(profiles, 'user.email').reverse()); 
    }); 
} 
関連する問題