Can we access unsaved record data from store?

On first page, I have created record as…

var item = this.store.createRecord(‘item’);

Which is created in store, but not saved to my server side.

Now I went ahead, can i access the above unsaved record in another controller?

Actually, am accepting details on two pages(first page- accepting few details of item, next page- more details of item).

Now I have used localStorage of browser to store the details entered on first page, and on 2nd page created record and merge details?.. but due to this the changes are not getting updated when i go back and add changes(no proper binding with values as part of data entered on first page shown on 2nd page.)

This is my first ember app… Anyone pls help me to fix this… Thanks.

I have the exact same question. Did you ever find a solution?

I use https://github.com/nolanlawson/ember-pouch and it fixes this out-of-the-box. Example: GitHub - broerse/ember-cli-blog: Tom Dale's blog example updated for the Ember CLI

Thanks for this solution. However, I presume this is only an option if I was using PouchDB/CouchDB, which I’m not, correct?

I’m testing a solution know where I loop over the current records in store and check for the record with no id set. Not ideal, but should do the job.

Correct and not. I was thinking about the original question and it could be solved with only Pouch and storing the end result on the backend. PouchDB works out-of-the box without a CouchDB backend. Just don’t sync.

In Ember.Data it is also possible to use this. Just create a record and you will get the record back via store.find(model, properties) or store.findAll(model) - persisted or not.

Can you do this without accessing the backend, perhaps by filtering on PeekAll? It has to be possible, I mean the EMber Inspector does just this:

this.store.peekAll(‘match’).findBy(‘isNew’, true);

where “match” is the name of my model.

I guess this is good enough for now :slight_smile:

2 Likes