You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure in which cases ember doesn't returns promises for relations (it seems to be the standard behaviour with ember-data, even for async=false relationship), but in case it helps this is how I changed your code to work with promises (haven't checked if hasMany relationships work yet):
importRecordForSynchronizationfrom'ember-sync/record-for-synchronization';importEmberfrom'ember';varalreadyRun=false;exportdefault{name: 'override-ember-sync',initialize: function(){if(alreadyRun){return;}else{alreadyRun=true;}RecordForSynchronization.reopen({toEmberData: function(){var_this=this,record;returnnewEmber.RSVP.Promise(function(resolve,reject){record=_this.createRecordInStore();_this.setRelationships(record).then(function(rec){resolve(rec);});});},setRelationships: function(pendingRecord){var_this=this,offlineRecord=this.get('offlineRecord'),type=this.get('jobRecord.jobRecordType');/** * We need to loop relationships. If no record was * passed in, we need to create a new one, fake, so we know about the * relationships. */if(!offlineRecord){offlineRecord=this.onlineStore.push(type,{id: 1});}varpromises=[];offlineRecord.eachRelationship(function(name,descriptor){varkey=descriptor.key,kind=descriptor.kind,type=descriptor.type,relation,onlineRelation;/** * TODO - implement for when `.get(relation)` returns a Promise. */promises.push(offlineRecord.get(name).then(function(relation){/** * We need to attach relationships to the main record. If the * relationships don't exist anymore offline, we need to generate a new * one, fake, with the same ID, just to send to the server. */if(kind=="belongsTo"){varrelationId=_this.get('jobRecord.serialized')[name];if(relationId&&!relation){relation=_this.onlineStore.push(type,{id: relationId});}if(relation){onlineRelation=_this.generateRelationForRecord(type,relation);pendingRecord.set(key,onlineRelation);}}elseif(kind=="hasMany"){relation.forEach(function(relation){onlineRelation=_this.generateRelationForRecord(type,relation);pendingRecord.get(name).pushObject(onlineRelation);});}returnpendingRecord;}));});returnEmber.RSVP.all(promises).then(function(res){returnpendingRecord;});},});},}
The text was updated successfully, but these errors were encountered:
I'm not sure in which cases ember doesn't returns promises for relations (it seems to be the standard behaviour with ember-data, even for async=false relationship), but in case it helps this is how I changed your code to work with promises (haven't checked if hasMany relationships work yet):
The text was updated successfully, but these errors were encountered: