genkgo / ember-localforage-adapter

Offline usage for Ember Data, based on localstorage adapter, but now uses Mozilla's localforage as data source
Other
133 stars 26 forks source link

id's #50

Closed acerov closed 9 years ago

acerov commented 9 years ago

Hi,

I am probably missing something but I cannot save record with my own integer id, it is always replaced with hash generated by localForage.

frederikbosch commented 9 years ago

This might very well be true.

frederikbosch commented 9 years ago

Actually, this implemented by Ember Data itself. The localforage adapter just implements this method. If you want to have your own generator (e.g. uuid), then you can overload the generateIdForRecord method.

import LFAdapter from 'ember-localforage-adapter/adapters/localforage';

export default LFAdapter.extend({
  generateIdForRecord: function(store, inputProperties) {
    var id = 'your id generation here';
    return id;
  }
});
acerov commented 9 years ago

Thnx, actually I do not want to replace generateIdForRecord just to bypass it when id is already set through setProperties, it is fine for me to be generated when id is not set. Hope I do not ask too much :)

acerov commented 9 years ago

I tried to implement generateIdForRecord in a way that when id is set then keep that id otherwise generate uuid but am facing this https://github.com/emberjs/data/issues/2516 and cannot access already set id. I use ember-data 1.13.8 Do you know some better way to accomplish this?

frederikbosch commented 9 years ago

@acerov If I lookup the line where generateIdForRecord is called in ED, it seems that now three arguments are passed. First the store, second the modelName and third the properties.

If I am right, I would appreciate if you create a PR with a documentation update, because this doc is then out-of-date.

acerov commented 9 years ago

@frederikbosch yes I saw that but third argument, console.log(properties) gives me just Object {}

frederikbosch commented 9 years ago

In that case I'd ask to reopen that issue. Or, even better, create a PR that solves it.

acerov commented 9 years ago

I ended up using push method which is more appropriate for my case which is to store locally records that exist on server.

frederikbosch commented 9 years ago

Sounds logical to me!