如何使用Strongloop Loopback REST API来包含和sorting数组?

我已经在现有的模型中包含了一个数组,在一个名为User / Questions的模型中添加了术语{"include" : ["answers"]} 。 因此,如果我得到用户/问题模型,我会得到一个答案列表。 但是,现在我想要在基于dateCreated的问题模型中排列答案。 要做到这一点,我应该如何编辑我放在REST Strongloop APIfilter中的术语?

 //QuestionModel [ { "question": "where is the coffee shop?" "answers": [ //answer model included { "answer": "I am not sure", "dateCreated": 4/1/16, }, { "answer": "maybe try 5th avenue?", "dateCreated": 4/3/16, }, { "answer": "oh its by the bakery", "dateCreated": 4/2/16, } ] 

当查询相关模型时,需要包含范围。 所以对于你的例子来说,这将是:

  {"include": {"relation": "answers", "scope": {"order" : "dateCreated DESC"}}}