Skip to content

Commit

Permalink
Clarifying error message for polymorphic types
Browse files Browse the repository at this point in the history
  • Loading branch information
pete committed Jul 5, 2018
1 parent 6d897be commit 8150921
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion addon/-debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ if (DEBUG) {
let relationshipModelName = relationshipMeta.type;
let relationshipClass = store.modelFor(relationshipModelName);
let addedClass = store.modelFor(addedInternalModel.modelName);
let assertionMessage = `You cannot add a record of modelClass '${addedModelName}' to the '${parentModelName}.${key}' relationship (only '${relationshipModelName}' allowed)`;

let assertionMessage = `The '${addedModelName}' type does not implement '${relationshipModelName}' and thus cannot be assigned to the '${key}' relationship in '${parentModelName}'. Make it a descendant of ${parentModelName} or use a mixin of the same name.`;

assert(assertionMessage, checkPolymorphic(relationshipClass, addedClass));
};
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ testInDebug('assertPolymorphicType works for subclasses', function(assert) {

assert.expectAssertion(() => {
assertPolymorphicType(user, relationship, person, env.store);
}, "You cannot add a record of modelClass 'person' to the 'user.messages' relationship (only 'message' allowed)");
}, "The 'person' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of user or use a mixin of the same name.");
});

test('modelHasAttributeOrRelationshipNamedType', function(assert) {
Expand Down Expand Up @@ -147,5 +147,5 @@ testInDebug('assertPolymorphicType works for mixins', function(assert) {

assert.expectAssertion(() => {
assertPolymorphicType(post, relationship, person, env.store);
}, "You cannot add a record of modelClass 'person' to the 'post.medias' relationship (only 'medium' allowed)");
}, "The 'person' type does not implement 'medium' and thus cannot be assigned to the 'medias' relationship in 'post'. Make it a descendant of post or use a mixin of the same name.");
});

0 comments on commit 8150921

Please sign in to comment.