如何使用 Strongloop Loopback REST API 包含和排序数组?
How to include and order an array using the Strongloop Loopback REST API?
我已经通过添加术语在现有模型中包含一个数组
{"include" : ["answers"]}
在名为 User/Questions 的模型中。因此,如果我得到 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"}}}
我已经通过添加术语在现有模型中包含一个数组
{"include" : ["answers"]}
在名为 User/Questions 的模型中。因此,如果我得到 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"}}}