2016-05-03 6 views
2

私は、ユーザ/質問というモデルに {"include" : ["answers"]}という用語を追加して、既存のモデルに配列を組み込んでいます。したがって、私がUser/Questionsモデルを取得した場合は、回答リストを取得します。しかし、今度は、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"}}} 
関連する問題