Dom
Dom

Reputation: 404

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

Upvotes: 4

Views: 1482

Answers (1)

Ember Freak
Ember Freak

Reputation: 12872

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

Upvotes: 8

Related Questions