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

Route with store.findAll not working correctly if records of that type already present from previous page #3863

Closed
adam-knights opened this issue Oct 16, 2015 · 1 comment

Comments

@adam-knights
Copy link
Contributor

Originally posted against Ember emberjs/ember.js#12488.

This was working fine with Ember 1.13.10 and Ember Data 1.13.12, doesn't seem to work with Ember 2.1.0 and Ember data 2.1.0.

If I navigate to http://localhost:4200/orders then it works fine and I see 6 orders come in from the api and the page displays information on all seven orders.

If I first navigate to http://localhost:4200/members/1234/orders, then I correctly see 3 orders from that member account. However, if I now press the link to goto http://localhost:4200/orders it only displays the same 3 orders. The api is deffinitely hit again and it correctly returns 6 orders.

I put a breakpoint at the end of Ember Data's _findAll method and its returning an array with 6 items from the return store.peekAll(modelName); line. Where else could things be going wrong? (More than happy to debug myself)

This is my orders route:

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin, {
  model: function() {
    return this.store.findAll('order').then(function(orders) {
      return orders.sortBy('creationDate').reverse();
    });
  },
  afterModel: function(orders) {
    document.title = 'Orders';
    return Ember.RSVP.all(orders.getEach('orderItems'));
  }
});

This is my account (member) model:

import DS from 'ember-data';

export default DS.Model.extend({
  accountType: DS.hasMany('accountType', {async: true}),
  addresses: DS.hasMany('address', {async: true}),
  contacts: DS.hasMany('contact', {async: true}),
  membershipType: DS.belongsTo('membershipType', {async: true}),
  communicationsAvailable: function() {
    var commsAvailable = [];
    this.get('contacts').forEach(contact => commsAvailable.push.apply(commsAvailable, contact.get('communicationsAvailable')));

    return commsAvailable.filter(function(value, index, ca) {
      return ca.indexOf(value) === index;
    });
  }.property('contacts.@each.communicationsAvailable'),
  joinDate: DS.attr('date'),
  name: DS.attr('string'),
  orders: DS.hasMany('order', {async: true}),
  prices: DS.hasMany('price', {async: true}),
  supplierCode: DS.attr('string')
});

This is my order model:

import DS from 'ember-data';

export default DS.Model.extend({
  account: DS.belongsTo('account', {async: true}),
  address: DS.belongsTo('address', {async: true}),
  collect: DS.attr('boolean'),
  deliveryDate: DS.attr('date'),
  paymentDate: DS.attr('date'),
  memberPurchaseOrderNumber: DS.attr('string'),
  orderItems: DS.hasMany('orderItem', {async: true}),
  orderNotes: DS.hasMany('orderNotes', {async: true}),
  orderNotifications: DS.hasMany('orderNotifications', {async: true}),
  orderStatus: DS.belongsTo('orderStatus', {async: true}),
  creationDate: DS.attr('date')
});
@adam-knights
Copy link
Contributor Author

Stefan now thinks this might be an ember issue. I'll close here for now and reopen if required.

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

1 participant