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

[BUGFIX beta] Inverse null relationships should throw if model doesn't exist 3 #4718

Merged
merged 2 commits into from
Dec 15, 2016
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
5 changes: 5 additions & 0 deletions addon/-private/system/relationships/state/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Ember from 'ember';
import ManyRelationship from "ember-data/-private/system/relationships/state/has-many";
import BelongsToRelationship from "ember-data/-private/system/relationships/state/belongs-to";
import EmptyObject from "ember-data/-private/system/empty-object";
import { runInDebug } from 'ember-data/-private/debug';

const { get } = Ember;

Expand All @@ -16,6 +17,10 @@ function createRelationshipFor(internalModel, relationshipMeta, store) {

if (shouldFindInverse(relationshipMeta)) {
inverse = internalModel.type.inverseFor(relationshipMeta.key, store);
} else {
runInDebug(() => {
internalModel.type.typeForRelationship(relationshipMeta.key, store);
});
}

if (inverse) {
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/relationships/inverse-relationships-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,17 @@ test("inverseFor is only called when inverse is not null", function(assert) {
});
});
});

testInDebug("Inverse null relationships with models that don't exist throw a nice error", function(assert) {
User = DS.Model.extend({
post: DS.belongsTo('post', { inverse: null })
});

var env = setupStore({ user: User });

assert.throws(function() {
run(function() {
env.store.createRecord('user');
});
}, /No model was found for 'post'/);
});
3 changes: 2 additions & 1 deletion tests/unit/debug-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ test("_debugInfo supports arbitray relationship types", function(assert) {
options: { inverse: null },
isRelationship: true,
kind: 'customRelationship',
name: 'Custom Relationship'
name: 'Custom Relationship',
type: 'post'
})
});

Expand Down