我通过添加术语在现有模型中包含一个数组
{"include": ["answers"]}
在名为 User/Questions 的模型中。因此,如果我获得用户/问题模型,我将获得答案列表。但是,现在我想根据创建日期对问题模型中的答案进行排序。为此,我应该如何编辑放置在 REST Strongloop API 过滤器中的术语?
//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,
}
]
最佳答案
范围需要包含在当 querying related models 时。因此,对于您的示例,它将类似于:
{"include": {"relation": "answers", "scope": {"order" : "dateCreated DESC"}}}
关于android - 如何使用 Strongloop Loopback REST API 包含和排序数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37012376/