我在一个现有的模型中加入了一个数组,通过添加{"include" : ["answers"]}
在一个叫做用户/问题的模型中。因此,如果我得到用户/问题模型,我将得到一个答案列表。但是,现在我想根据创建的日期在问题模型中排序答案。要做到这一点,我应该如何编辑放置在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/