Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a better error message when malformatted JSON API is pushed into … #4908

Merged
merged 1 commit into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon/-private/system/relationships/state/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export default class BelongsToRelationship extends Relationship {
}

updateData(data, initial) {
assert(`Ember Data expected the data for the ${this.key} relationship on a ${this.internalModel.toString()} to be in a JSON API format and include an \`id\` and \`type\` property but it found ${Ember.inspect(data)}. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`, data === null || data.id !== undefined && data.type !== undefined);
let internalModel = this.store._pushResourceIdentifier(this, data);
if (initial) {
this.setInitialCanonicalRecord(internalModel);
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1364,3 +1364,22 @@ test("A belongsTo relationship can be reloaded using a reference if it was fetch
});
});
});

testInDebug("A belongsTo relationship warns if malformatted data is pushed into the store", function(assert) {
assert.expectAssertion(function() {
run(function() {
let chapter = env.store.push({
data: {
type: 'chapter',
id: 1,
relationships: {
book: {
data: { id: 1, name: 'The Gallic Wars' }
}
}
}
});
chapter.get('book');
});
}, /expected the data for the book relationship on a <chapter:1> to be in a JSON API format/);
});