如何从我的收藏中返回与某些自定义ID(不是常规ID)匹配的记录?
// 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文档仅引用了' find()'作用于id的函数,以及' where()'获得一系列记录。
答案 0 :(得分:0)
从models数组中选择第一个元素!
var device = db.devices.where({'dId' : did });
return device.models[0];