How to refresh ember model on creating new record


#1

I tried to create a new record in a route using createRecord method and I persisted it using .save() method.

it is getting saved in db and showing record in my view component.

but I am generating id on my db. but when i check id is showing as null.

I think the model is not refreshing automatically on creating new record.

when I manually refresh page the record is showing with id


#2

What data does your API return? It sounds like Ember isn’t able to extract the ID from the API response.


#3

I am getting response from db with id. but it is not automatically refreshing store


#4

I am sure you are getting a response but unless it is in the exact form ember expects then it will not automatically extract the ID and update the store. Take a look into the normalizeResponse, specifically normalizeSaveResponse which is the hook you can use after saving a record.


#5

but when I refresh the page the record is updating with id.

So I think the problem is data store is not automatically updating on creating new record.

But it is updating on refreshing page. I found this difference using ember inspector in chrome and I had a watch on ember data in ember inspector


#6

And I have a doubt will ember data get refreshed automatically on creating new record . ie, will it display the get response from db automatically??


#7

were you ever able to find an answer to this? I am having the same issue, but no luck. I’ve seen alot of questions like this from several years back, which included workarounds, but none of the workarounds really worked for me. Basically, i only get back the data that i included in the “CreateRecord” part, but not the id that came from the server.


#8

Having the same issue. @rpcollins were you ever able to solve this?


#9

Unfortunately not. I ended up just writing an ajax call and bypassing the adapter/store for that particular call.


#10

I have face this type of issue and solved it by simply using :

beforeModel() {
   this.store.unloadAll('PARTICULAR MAODEL NAME');
}

Not the right way. But, It solved the problem.