2016-05-03 93 views
2

我在現有模型中添加了一個數組,在名爲User/Questions的模型中添加了術語 {"include" : ["answers"]}。因此,如果我得到用戶/問題模型,我會得到一個答案列表。但是,現在我想根據dateCreated在我的問題模型中排列答案。爲此,我應該如何編輯我放置在REST Strongloop API過濾器中的術語?如何使用Strongloop Loopback REST 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, 
    } 
] 

回答

1

範圍需要包括在當querying related models。因此,對於您的示例,這將是沿線:

{"include": {"relation": "answers", "scope": {"order" : "dateCreated DESC"}}} 
相關問題