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 deprecation to relationships without { async: false } #3283

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions packages/ember-data/lib/system/relationships/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function belongsTo(modelName, options) {

opts = opts || {};

if (typeof opts.async === 'undefined') {
Ember.deprecate('In the future, relationships will be asynchronous by default. You must set { async: false } if you wish for a relationship remain synchronous.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add which relationship to the deprecation notice please. This way it will be much more annoying to track down.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like model type, relationship key, etc.

}

var meta = {
type: userEnteredModelName,
isRelationship: true,
Expand Down
4 changes: 4 additions & 0 deletions packages/ember-data/lib/system/relationships/has-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ function hasMany(type, options) {

options = options || {};

if (typeof options.async === 'undefined') {
Ember.deprecate('In the future, relationships will be asynchronous by default. You must set { async: false } if you wish for a relationship remain synchronous.');
}

if (typeof type === 'string') {
type = normalizeModelName(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,22 @@ test("belongsTo gives a warning when provided with an embedded option", function
});
}, /You provided an embedded option on the "hobby" property in the "person" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin/);
});

module("unit/model/relationships - DS.belongsTo async by default deprecations", {
setup: function() {
setupStore();
}
});

test("setting DS.belongsTo without async false triggers deprecation", function() {
expectDeprecation(
function() {
run(function() {
DS.Model.extend({
post: DS.belongsTo('post')
});
});
},
'In the future, relationships will be asynchronous by default. You must set { async: false } if you wish for a relationship remain synchronous.'
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,22 @@ test("it is possible to add an item to a relationship, remove it, then add it ag
equal(tags.objectAt(1), tag1);
equal(tags.objectAt(2), tag3);
});

module("unit/model/relationships - DS.hasMany async by default deprecations", {
setup: function() {
env = setupStore();
}
});

test("setting DS.hasMany without async false triggers deprecation", function() {
expectDeprecation(
function() {
run(function() {
DS.Model.extend({
comments: DS.hasMany('comment')
});
});
},
'In the future, relationships will be asynchronous by default. You must set { async: false } if you wish for a relationship remain synchronous.'
);
});