Deal with undefined records in store during record generation? (new in 2.13)


In upgrading to 2.13 from 2.11 I have a recurring problem where records being created don’t show up in peekAll() or peekRecord() calls with their data intact. During record creation there is some ‘undefined’ record in the store that clashes with various functions during record creation.

For instance, during the generation of a ‘part’ record, I want to ensure children don’t conflict with any existing children, so I ask the store to help find conflicts. However, if multiple children are being created in a loop somewhere else then the peekAll never finds any siblings - and conflicts occur. This behavior did not happen in 2.11.

ensureUniqueChildNames: function(){
var childrenWithName = store.peekAll('children').filterBy('name',proposedName);`
if (childrenWithName){
//there is a conflict      /////////// <----- Never fires in Ember 2.13, DID fire in 2.11
// no conflict

This function now crashes the ember app when two children are created at once. When this function is run by the second child, an error occurs:

Assertion Failed: Cannot call get with ‘name’ on an undefined object.

Which is ultimately being called when the first child (which has been assigned a name) is being accessed by the store during: store.peekAll(‘part’).filterBy(‘name’) Somehow that first child is ‘undefined’, but is still in the store.

Another example, I have an adapter that uses an incremented ID in its generateIdForRecord() function. However, if multiple objects are created in a row, the ‘store’ called from within the generateIdForRecord function somehow does not have access to any of the other objects that are being created - so there is no way to increment the ID of a bunch of records being created - and they have conflicting IDs:

for (1-10){

and in adapter/part.js:

generateIdForRecord: function(){
var id = 0;
return id;

I think the Ember Inspector in chrome also fails to see the new objects as they are being created in the store until some later time.

Any thoughts on how to deal with this strange (new) behavior of the store found in 2.13? What is going on here? Is there a state change to the record that is not being triggered? How can there by ‘undefined’ objects when returning the result of a store.peekRecord(‘kind’) request?


It seems I can get around some of the issues by removing null records prior to filtering - but that seems like an undesirable behavior.

var allPartsNamedFoo = this.get('store').peekAll('part').without(null).filterBy('name','Foo');
// successful

where otherwise it fails in 2.13

var allPartsNamedFoo= this.get('store').peekAll('part').filterBy('name','Foo');
// crashes in 2.13, successful in 2.11