2016-07-13 31 views
0

我怎樣才能返回,從我收集匹配一些自定義的ID(不固定的id)記錄?獲取單個記錄在灰燼-CLI-海市蜃樓

// record schema 
{ 
    id: 123,   // assigned id from mirage 
    dId: 'DEVICE0001', // device id I want to use to pick 
    value: 'some content' 
} 

要使用這樣的選擇:

// app/mirage/config.js 
this.get("/something/:device_did", function(db, request){ 
     var did = request.params.device_did; 

     // select using my device id 
     return db.devices.firstWhere({ 'dId': did }); 
    }); 

API文檔只引用了「發現()函數作用於ID和「其中()」是得到一個數組的記錄。

回答

0

選擇的車型陣列的第一要素!

var device = db.devices.where({'dId' : did }); 
return device.models[0];