Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to peek a record using name rather then using id in ember

So in rails we could find a record by name, id etc, similarly i want to do in ember without making a server request I have a model called person{id, name}. If i want to peek a record by id i do this:

this.get('store').peekRecord('person', id)

which gives me the record based on id, but now i want to peek a record with a particular name, i tried something like this:

this.get('store').peekRecord('person', {name: "testname"}) 

which dose not seem to work. i need a way peek a record using just the name

like image 557
Dom Avatar asked Feb 05 '23 11:02

Dom


1 Answers

You can only peekRecord using the unique identifier for the model, which is id property. If you do want to make a request then queryRecord is what you want. but you don't want to make a request so the only choice is peekAll and filter the result,

let allRecord = this.get('store').peekAll('person');
let filteredResult = allRecord.filterBy('name','testname');
//filteredResult is an array of matching records
like image 199
Ember Freak Avatar answered Mar 03 '23 07:03

Ember Freak