From c54e7a140f2b4948c6c31b1c9becf9e1a3cd6198 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Wed, 30 Nov 2016 10:44:43 -0800 Subject: [PATCH] for debugging, ensure arg name is modelName but don't overwrite it with the normalized trueModelName --- addon/-private/system/store.js | 108 ++++++++++++++++----------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/addon/-private/system/store.js b/addon/-private/system/store.js index dcd69c7063b..8b0d7d35d36 100644 --- a/addon/-private/system/store.js +++ b/addon/-private/system/store.js @@ -326,7 +326,7 @@ Store = Service.extend({ createRecord(modelName, inputProperties) { assert("You need to pass a model name to the store's createRecord method", isPresent(modelName)); assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${inspect(modelName)}`, typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); let properties = copy(inputProperties) || new EmptyObject(); // If the passed properties do not include a primary key, @@ -335,13 +335,13 @@ Store = Service.extend({ // to avoid conflicts. if (isNone(properties.id)) { - properties.id = this._generateId(modelName, properties); + properties.id = this._generateId(trueModelName, properties); } // Coerce ID to a string properties.id = coerceId(properties.id); - let internalModel = this.buildInternalModel(modelName, properties.id); + let internalModel = this.buildInternalModel(trueModelName, properties.id); let record = internalModel.getRecord(); // Move the record out of its initial `empty` state into @@ -448,9 +448,9 @@ Store = Service.extend({ assert("You cannot pass `" + inspect(id) + "` as id to the store's find method", typeOf(id) === 'string' || typeOf(id) === 'number'); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); - return this.findRecord(modelName, id); + return this.findRecord(trueModelName, id); }, /** @@ -658,18 +658,18 @@ Store = Service.extend({ assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); assert(badIdFormatAssertion, (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && !isNaN(id))); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); - let internalModel = this._internalModelForId(modelName, id); + let internalModel = this._internalModelForId(trueModelName, id); options = options || {}; - if (!this.hasRecordForId(modelName, id)) { + if (!this.hasRecordForId(trueModelName, id)) { return this._findByInternalModel(internalModel, options); } let fetchedInternalModel = this._findRecord(internalModel, options); - return promiseRecord(fetchedInternalModel, "DS: Store#findRecord " + internalModel.typeKey + " with id: " + get(internalModel, 'id')); + return promiseRecord(fetchedInternalModel, `DS: Store#findRecord ${trueModelName} with id: ${id}`); }, _findRecord(internalModel, options) { @@ -740,13 +740,13 @@ Store = Service.extend({ assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); let promises = new Array(ids.length); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); for (let i = 0; i < ids.length; i++) { - promises[i] = this.findRecord(modelName, ids[i]); + promises[i] = this.findRecord(trueModelName, ids[i]); } - return promiseArray(RSVP.all(promises).then(A, null, "DS: Store#findByIds of " + modelName + " complete")); + return promiseArray(RSVP.all(promises).then(A, null, `DS: Store#findByIds of ${trueModelName} complete`)); }, /** @@ -967,9 +967,9 @@ Store = Service.extend({ @return {RecordReference} */ getReference(modelName, id) { - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); - return this._internalModelForId(modelName, id).recordReference; + return this._internalModelForId(trueModelName, id).recordReference; }, /** @@ -997,10 +997,10 @@ Store = Service.extend({ heimdall.increment(peekRecord); assert("You need to pass a model name to the store's peekRecord method", isPresent(modelName)); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); - if (this.hasRecordForId(modelName, id)) { - return this._internalModelForId(modelName, id).getRecord(); + if (this.hasRecordForId(trueModelName, id)) { + return this._internalModelForId(trueModelName, id).getRecord(); } else { return null; } @@ -1053,10 +1053,10 @@ Store = Service.extend({ hasRecordForId(modelName, id) { assert("You need to pass a model name to the store's hasRecordForId method", isPresent(modelName)); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); let id = coerceId(inputId); - let internalModel = this._recordMapFor(modelName).idToRecord[id]; + let internalModel = this._recordMapFor(trueModelName).idToRecord[id]; return !!internalModel && internalModel.isLoaded(); }, @@ -1208,8 +1208,8 @@ Store = Service.extend({ assert(`You need to pass a query hash to the store's query method`, query); assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${inspect(modelName)}`, typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); - return this._query(modelName, query); + let trueModelName = this._classKeyFor(modelName); + return this._query(trueModelName, query); }, _query(modelName, query, array) { @@ -1327,12 +1327,12 @@ Store = Service.extend({ assert("You need to pass a model name to the store's queryRecord method", isPresent(modelName)); assert("You need to pass a query hash to the store's queryRecord method", query); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); - let modelClass = this.modelFor(modelName); - let adapter = this.adapterFor(modelName); + let modelClass = this.modelFor(trueModelName); + let adapter = this.adapterFor(trueModelName); - assert("You tried to make a query but you have no adapter (for " + modelName + ")", adapter); + assert(`You tried to make a query but you have no adapter (for ${trueModelName})`, adapter); assert("You tried to make a query but your adapter does not implement `queryRecord`", typeof adapter.queryRecord === 'function'); return promiseObject(_queryRecord(adapter, this, modelClass, query).then((internalModel) => { @@ -1539,9 +1539,9 @@ Store = Service.extend({ assert("You need to pass a model name to the store's findAll method", isPresent(modelName)); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); let token = heimdall.start('store.findAll'); - modelName = this._classKeyFor(modelName); - let modelClass = this.modelFor(modelName); - let fetch = this._fetchAll(modelClass, this.peekAll(modelName), options); + let trueModelName = this._classKeyFor(modelName); + let modelClass = this.modelFor(trueModelName); + let fetch = this._fetchAll(modelClass, this.peekAll(trueModelName), options); instrument(() => { fetch.finally(() => { heimdall.stop(token); }); @@ -1631,10 +1631,10 @@ Store = Service.extend({ heimdall.increment(peekAll); assert("You need to pass a model name to the store's peekAll method", isPresent(modelName)); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); - let liveRecordArray = this.recordArrayManager.liveRecordArrayFor(modelName); + let trueModelName = this._classKeyFor(modelName); + let liveRecordArray = this.recordArrayManager.liveRecordArrayFor(trueModelName); - this.recordArrayManager.syncLiveRecordArray(liveRecordArray, modelName); + this.recordArrayManager.syncLiveRecordArray(liveRecordArray, trueModelName); return liveRecordArray; }, @@ -1665,8 +1665,8 @@ Store = Service.extend({ recordMaps[key].clear(); } } else { - modelName = this._classKeyFor(modelName); - this._recordMapFor(modelName).clear(); + let trueModelName = this._classKeyFor(modelName); + this._recordMapFor(trueModelName).clear(); } }, @@ -1737,24 +1737,24 @@ Store = Service.extend({ let array; let hasQuery = length === 3; - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); // allow an optional server query if (hasQuery) { - promise = this.query(modelName, query); + promise = this.query(trueModelName, query); } else if (arguments.length === 2) { filter = query; } if (hasQuery) { - array = this.recordArrayManager.createFilteredRecordArray(modelName, filter, query); + array = this.recordArrayManager.createFilteredRecordArray(trueModelName, filter, query); } else { - array = this.recordArrayManager.createFilteredRecordArray(modelName, filter); + array = this.recordArrayManager.createFilteredRecordArray(trueModelName, filter); } promise = promise || Promise.resolve(array); - return promiseArray(promise.then(() => array, null, 'DS: Store#filter of ' + modelName)); + return promiseArray(promise.then(() => array, null, `DS: Store#filter of ${trueModelName}`)); }, /** @@ -2055,20 +2055,20 @@ Store = Service.extend({ assert("You need to pass a model name to the store's modelFor method", isPresent(modelName)); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); - let factory = this.modelFactoryFor(modelName); + let factory = this.modelFactoryFor(trueModelName); if (!factory) { //Support looking up mixins as base types for polymorphic relationships - factory = this._modelForMixin(modelName); + factory = this._modelForMixin(trueModelName); } if (!factory) { - throw new EmberError(`No model was found for '${modelName}'`); + throw new EmberError(`No model was found for '${trueModelName}'`); } assert(`'${inspect(factory)}' does not appear to be an ember-data model`, (typeof factory._create === 'function') ); - factory.modelName = factory.modelName || modelName; + factory.modelName = factory.modelName || trueModelName; return factory; }, @@ -2077,10 +2077,10 @@ Store = Service.extend({ heimdall.increment(modelFactoryFor); assert("You need to pass a model name to the store's modelFactoryFor method", isPresent(modelName)); assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ inspect(modelName), typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); let owner = getOwner(this); - return owner._lookupFactory(`model:${modelName}`); + return owner._lookupFactory(`model:${trueModelName}`); }, /** @@ -2414,8 +2414,8 @@ Store = Service.extend({ } else { payload = inputPayload; assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${inspect(modelName)}`, typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); - serializer = this.serializerFor(modelName); + let trueModelName = this._classKeyFor(modelName); + serializer = this.serializerFor(trueModelName); } if (isEnabled('ds-pushpayload-return')) { return this._adapterRun(() => { return serializer.pushPayload(this, payload); }); @@ -2447,9 +2447,9 @@ Store = Service.extend({ heimdall.increment(normalize); assert("You need to pass a model name to the store's normalize method", isPresent(modelName)); assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${inspect(modelName)}`, typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); - let serializer = this.serializerFor(modelName); - let model = this.modelFor(modelName); + let trueModelName = this._classKeyFor(modelName); + let serializer = this.serializerFor(trueModelName); + let model = this.modelFor(trueModelName); return serializer.normalize(model, payload); }, @@ -2545,9 +2545,9 @@ Store = Service.extend({ heimdall.increment(adapterFor); assert("You need to pass a model name to the store's adapterFor method", isPresent(modelName)); assert(`Passing classes to store.adapterFor has been removed. Please pass a dasherized string instead of ${inspect(modelName)}`, typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); - return this._instanceCache.get('adapter', modelName); + return this._instanceCache.get('adapter', trueModelName); }, _adapterRun(fn) { @@ -2583,9 +2583,9 @@ Store = Service.extend({ heimdall.increment(serializerFor); assert("You need to pass a model name to the store's serializerFor method", isPresent(modelName)); assert(`Passing classes to store.serializerFor has been removed. Please pass a dasherized string instead of ${inspect(modelName)}`, typeof modelName === 'string'); - modelName = this._classKeyFor(modelName); + let trueModelName = this._classKeyFor(modelName); - return this._instanceCache.get('serializer', modelName); + return this._instanceCache.get('serializer', trueModelName); }, lookupAdapter(name) {