Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find records from server, relationship array not pushed to offline store #34

Open
Leooo opened this issue Apr 14, 2015 · 1 comment
Open

Comments

@Leooo
Copy link

Leooo commented Apr 14, 2015

When using this.emberSync.find('post'), after fetching data from the server, the relationships are not pushed to the offline Store, only to the online Store: in ActiveModel serializer, extractArray pushes the relationships in the Store, while returning the primary Array. emberSync's find query uses the results returned by onlineSearch = this.onlineStore.find(type, query), which only returns the primary array.

To have the relationships pushed to the offlineStore, I had to override the ActiveModelSerializer:

export default DS.ActiveModelSerializer.extend({
 //(..)
  extractArray: function(store, primaryType, rawPayload) {
    //(..)
        if (isPrimary) {
          primaryArray = normalizedArray;
        } else {
          var records=this.container.lookup('store:main').pushMany(typeName, Ember.copy(normalizedArray,true));//added
          records.forEach(function(record){//added
            record.save();//added
          });//added
          store.pushMany(typeName, normalizedArray);
        }
      }
      return primaryArray;
    },

  extractSingle: function(store, primaryType, rawPayload, recordId) {
     //(..)
        if (isFirstCreatedRecord || isUpdatedRecord) {
          primaryRecord = hash;
        } else {
          var record=this.container.lookup('store:main').push(typeName, Ember.copy(hash,true));//added
          record.save();//added
          store.push(typeName, hash);
        }
      }, this);
    }
    return primaryRecord;
  },
@kurko
Copy link
Owner

kurko commented Jun 12, 2015

Could you open a PR with this? This is very good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants