Skip to content

Commit

Permalink
for debugging, ensure arg name is modelName but don't overwrite it wi…
Browse files Browse the repository at this point in the history
…th the normalized trueModelName
  • Loading branch information
runspired committed Nov 30, 2016
1 parent 1e594a2 commit c54e7a1
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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);
},

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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`));
},

/**
Expand Down Expand Up @@ -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;
},

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
},
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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); });
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -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();
}
},

Expand Down Expand Up @@ -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}`));
},

/**
Expand Down Expand Up @@ -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;
},
Expand All @@ -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}`);
},

/**
Expand Down Expand Up @@ -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); });
Expand Down Expand Up @@ -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);
},

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c54e7a1

Please sign in to comment.