Skip to content

Commit

Permalink
Update Ember.warn calls to include required options
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroicEric committed Jul 22, 2015
1 parent ea6f13e commit 9fc6689
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
9 changes: 5 additions & 4 deletions packages/ember-data/lib/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,11 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({
key = this.keyForAttribute(attr, 'serialize');
hasMany = snapshot.hasMany(attr);

Ember.warn("The embedded relationship '" + key + "' is undefined for '" +
snapshot.modelName +
"' with id '" + snapshot.id +
"'. Please include it in your original payload.", Ember.typeOf(hasMany) !== 'undefined');
Ember.warn(
`The embedded relationship '${key}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`,
Ember.typeOf(hasMany) !== 'undefined',
{ id: 'embedded-records-mixin.serialize-has-many-undefined', until: '3.0.0' }
);

json[key] = Ember.A(hasMany).map((embeddedSnapshot) => {
var embeddedJson = embeddedSnapshot.record.serialize({ includeId: true });
Expand Down
10 changes: 8 additions & 2 deletions packages/ember-data/lib/serializers/rest-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ var RESTSerializer = JSONSerializer.extend({

var typeName = this.modelNameFromPayloadKey(modelName);
if (!store.modelFactoryFor(typeName)) {
Ember.warn(this.warnMessageNoModelForKey(modelName, typeName), false);
Ember.warn(this.warnMessageNoModelForKey(modelName, typeName), false, {
id: 'serializers.rest-serializer.normalize-response.no-model-for-key',
until: '3.0.0'
});
continue;
}

Expand Down Expand Up @@ -334,7 +337,10 @@ var RESTSerializer = JSONSerializer.extend({
for (var prop in payload) {
var modelName = this.modelNameFromPayloadKey(prop);
if (!store.modelFactoryFor(modelName)) {
Ember.warn(this.warnMessageNoModelForKey(prop, modelName), false);
Ember.warn(this.warnMessageNoModelForKey(modelName, typeName), false, {
id: 'serializers.rest-serializer.push-payload.no-model-for-key',
until: '3.0.0'
});
continue;
}
var type = store.modelFor(modelName);
Expand Down
15 changes: 13 additions & 2 deletions packages/ember-data/lib/system/relationships/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,19 @@ function belongsTo(modelName, options) {

return Ember.computed({
get: function(key) {
Ember.warn('You provided a serialize option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.Serializer and it\'s implementations http://emberjs.com/api/data/classes/DS.Serializer.html', !opts.hasOwnProperty('serialize'));
Ember.warn('You provided an embedded option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html', !opts.hasOwnProperty('embedded'));
if (opts.hasOwnProperty('serialize')) {
Ember.warn(`You provided a serialize option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.Serializer and it's implementations http://emberjs.com/api/data/classes/DS.Serializer.html`, false, {
id: 'system.belongs-to.serialize-option-passed',
until: '3.0.0'
});
}

if (opts.hasOwnProperty('embedded')) {
Ember.warn(`You provided an embedded option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html`, false, {
id: 'system.belongs-to.embedded-option-passed',
until: '3.0.0'
});
}

return this._internalModel._relationships.get(key).getRecord();
},
Expand Down
9 changes: 7 additions & 2 deletions packages/ember-data/lib/system/relationships/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ Model.reopenClass({

var inverseName, inverseKind, inverse;

Ember.warn("Detected a reflexive relationship by the name of '" + name + "' without an inverse option. Look at http://emberjs.com/guides/models/defining-models/#toc_reflexive-relation for how to explicitly specify inverses.", options.inverse || propertyMeta.type !== propertyMeta.parentType.modelName);

//If inverse is specified manually, return the inverse
if (options.inverse) {
inverseName = options.inverse;
Expand All @@ -256,6 +254,13 @@ Model.reopenClass({
inverseKind = inverse.kind;
} else {
//No inverse was specified manually, we need to use a heuristic to guess one
if (propertyMeta.type === propertyMeta.parentType.modelName) {
Ember.warn(`Detected a reflexive relationship by the name of '${name}' without an inverse option. Look at http://emberjs.com/guides/models/defining-models/#toc_reflexive-relation for how to explicitly specify inverses.`, false, {
id: 'system.model.inverse-for-without-inverse-option',
until: '3.0.0'
});
}

var possibleRelationships = findPossibleInverses(this, inverseType);

if (possibleRelationships.length === 0) { return null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ Relationship.prototype = {
},

updateLink: function(link) {
Ember.warn("You have pushed a record of type '" + this.record.type.modelName + "' with '" + this.key + "' as a link, but the association is not an async relationship.", this.isAsync);
Ember.warn(`You have pushed a record of type '${this.record.type.modelName}' with '${this.key}' as a link, but the association is not an async relationship.`, this.isAsync, {
id: 'system.relationship.update-link-on-sync-relationship',
until: '3.0.0'
});
Ember.assert("You have pushed a record of type '" + this.record.type.modelName + "' with '" + this.key + "' as a link, but the value of that link is not a string.", typeof link === 'string' || link === null);
if (link !== this.link) {
this.link = link;
Expand Down
8 changes: 6 additions & 2 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,10 @@ Store = Service.extend({
resolvedRecords = Ember.A(resolvedRecords);
var missingRecords = requestedRecords.reject((record) => resolvedRecords.contains(record));
if (missingRecords.length) {
Ember.warn('Ember Data expected to find records with the following ids in the adapter response but they were missing: ' + Ember.inspect(Ember.A(missingRecords).mapBy('id')), false);
Ember.warn('Ember Data expected to find records with the following ids in the adapter response but they were missing: ' + Ember.inspect(Ember.A(missingRecords).mapBy('id')), false, {
id: 'system.store.missing-records',
until: '3.0.0'
});
}
rejectRecords(missingRecords);
};
Expand Down Expand Up @@ -1624,7 +1627,8 @@ Store = Service.extend({
})) + ". Make sure they've been defined in your model.",
Object.keys(data).filter((key) => {
return !(key === 'id' || key === 'links' || get(type, 'fields').has(key) || key.match(/Type$/));
}).length === 0
}).length === 0,
{ id: 'system.store.push-unknown-keys', until: '3.0.0' }
);
}

Expand Down

0 comments on commit 9fc6689

Please sign in to comment.