Domanda

I am writing an Ember-Data adapter for the Rhom API. I have written the code. I am using it in a simple Todo App. When I create a new item, it gets into the SQLite db. But when I start the app, the already existing ones donot get loaded in the store.

I wrote a console.log in the findAll of my adapter and I can see that it gets an object array from the Rhom API and returns a promise with those results. But why does it not load into the store?

I used the localstorage-adapter as an example and did this. Here is my findAll:

 extractVars: function(rhomRecord) {
    return rhomRecord.vars();
},

sourceIdToId: function(record) {
    record["id"] = record.source_id;
    return record;
},

findAll: function(store, type) {
        var records = Rho.ORM.getModel(this.model).find('all');
        var results = records.map(this.extractVars);
        var results = results.map(this.sourceIdToId);
        console.log(results);
        return Ember.RSVP.resolve(results);
    },

As you can see, the console.log prints the following out and its just an array of objects that contain what I need. When I tried with the locastorate, it also returned a same kind of objects.

What do I do?

enter image description here

PS: The extractVars and sourceIdtoId are auxillary to propery extract the objects from the records returned by Rhom.

È stato utile?

Soluzione

I'm not really sure if this will help you but I guess just because .find() returns a promise you should use the .then() callback to resolve your model:

findAll: function(store, type) {
  return Rho.ORM.getModel(this.model).find('all').then(function(records) {
    var results = records.map(this.extractVars);
    var results = results.map(this.sourceIdToId);
    console.log(results);
    return Ember.RSVP.resolve(results);
  });
}

Hope it helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top