installed versions
ember-cli 2.14.2 ember-data 2.14.10
Small perspective:
I have a service called menu that executes storage queries inside computed properties. One of these in-store queries behaves rather strangely. It extracts all records under the product-segment model name from the fully functional JSON API. This model has an nn relationship with a model called product referenced by hasMany DS objects:
models / product-segment.js
export default DS.Model.extend({ products: DS.hasMany('product'), // ... });
models / product.js
export default DS.Model.extend({ productSegments: DS.hasMany('product-segment'), // ... })
Problem:
Now, when I retrieve these product-segment models, I instruct the API { include: 'products' } , and the API does this as it is requested. The answer includes 15 related product models for a particular product-segment , which is true.
(let this segment product-segment segment x , this is the topic for all my debugging information below)
However, access to the collection of relationships in segment x segment from any context, at any time, returns me only 12 models, so 3 are missing. I have observed similar problems with other product-segment models, so I don't think this is a problem with one specific model.
More promising
At first it seemed to me that I was dealing with a specific race condition, and, of course, I created a calculated property - test - to find out, and I dropped {{menu.test}} into my point of view to tickle the calculated support.
Here is the minimal info inside services/menu.js
export default Service.extend({ store: inject(), activeProductSegment: null,
The activeProductSegment property activeProductSegment set in different instances of the product-segment model through the action of the component, which looks like this:
export default Component.extend({ menu: inject(), // menu service is injected here... actions: { setProductSegment(segment) { get(this, 'menu').set('activeProductSegment', segment); } } });
The action itself works as expected, and is in fact completely unrelated to my problem. activeProductSegment never updated in any other way. The view passes this action to product-segment objects of the model:
{{#each menu.productSegments as |segment|}} <li {{action 'setProductSegment' segment}}>{{segment.name}}</li> {{/each}}
The problem starts here.
I set menu.activeProductSegment to segment x by clicking its associated <li> element.
When I try to get all related product models of segment x , only 12 out of 15 models are present in the returned collection. To be sure that the JSON response was indeed right (i.e. type definitions, etc.), I checked the number of product identifiers registered in the x segment. I registered the following line (the log context below is given in the Ember.Service above):
console.log(segment.hasMany('products').ids());
This returned me an array with 15 valid identifiers, so the x segment has all id as expected. All product models of these identifiers were included in the response, so I suppose there should not be any problems with asynchronous data. However, the following line returned an array of 12 identifiers to me:
console.log(get(segment, 'products').mapBy('id'));
I tried putting 2 logs in a 2 second setTimeout , but the result remained identical:

I'm starting to think that this is a mistake, since I noticed that the first time the id was not followed by the model, this is when the first identifier is lower than the previous one.
Update above . In the answer, I tried a different order, and pay attention to the second and third identifiers: "7", "6" . Guess this is not a problem:

If I donβt understand, the models should be alive, so any relationship should be updated as data becomes available. I think it is unlikely that this has anything to do with garbled data.
What could be the reason for the missing models in the hasMany association hasMany , despite the fact that all the necessary identifiers are properly registered in the hasMany relationship hasMany , and we do not need to wait for any asynchronous / network data to arrive at the moment? And what could be a suitable solution to the problem?