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

deprecation: implement strict relationships #8115

Merged
merged 12 commits into from
Aug 12, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Pet extends Model {
@belongsTo('person', { inverse: 'bestDog', async: false })
bestHuman;
// inverse is an implicit hasMany relationship
@belongsTo('person', { async: true })
@belongsTo('person', { async: true, inverse: null })
petOwner;
@attr()
name;
Expand Down
4 changes: 2 additions & 2 deletions packages/-ember-data/tests/dummy/app/models/foo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Model, { attr, belongsTo, hasMany } from '@ember-data/model';

export default class Foo extends Model {
@attr name;
@belongsTo('foo', { async: false }) parent;
@hasMany('foo', { async: false }) children;
@belongsTo('foo', { async: false, inverse: 'children' }) parent;
@hasMany('foo', { async: false, inverse: 'parent' }) children;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - with relative paths in links', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand All @@ -92,11 +92,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - with absolute paths in links', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand All @@ -119,11 +119,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - with absolute paths in links and protocol relative host', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand All @@ -146,11 +146,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - with absolute paths in links and host is /', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand All @@ -173,11 +173,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - with full URLs in links', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand Down Expand Up @@ -221,11 +221,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - buildURL takes a record from find', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand All @@ -252,11 +252,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - buildURL takes the records from findMany', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand Down Expand Up @@ -294,11 +294,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - buildURL takes a record from create', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand All @@ -325,11 +325,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - buildURL takes a record from create to query a resolved async belongsTo relationship', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: true }) post;
@belongsTo('post', { async: true, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand Down Expand Up @@ -362,11 +362,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - buildURL takes a record from update', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: true }) comments;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand Down Expand Up @@ -399,11 +399,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - buildURL takes a record from delete', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: false }) comments;
@hasMany('comment', { async: false, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand Down Expand Up @@ -438,11 +438,11 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f
test('buildURL - with absolute namespace', async function (assert) {
class PostModel extends Model {
@attr('string') name;
@hasMany('comment', { async: false }) comments;
@hasMany('comment', { async: false, inverse: 'post' }) comments;
}
class CommentModel extends Model {
@attr('string') name;
@belongsTo('post', { async: false }) post;
@belongsTo('post', { async: false, inverse: 'comments' }) post;
}

this.owner.register('model:post', PostModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks)
class User extends Model {
@attr('string') firstName;
@attr('string') lastName;
@hasMany('post', { async: true }) posts;
@hasMany('handle', { async: true, polymorphic: true }) handles;
@belongsTo('company', { async: true, polymorphic: true }) company;
@hasMany('post', { async: true, inverse: 'author' }) posts;
@hasMany('handle', { async: true, inverse: 'user', polymorphic: true }) handles;
@belongsTo('company', { async: true, inverse: 'employees', polymorphic: true }) company;
}

class Post extends Model {
@attr('string') title;
@belongsTo('user', { async: true }) author;
@hasMany('comment', { async: true }) comments;
@belongsTo('user', { async: true, inverse: 'posts' }) author;
@hasMany('comment', { async: true, inverse: 'post' }) comments;
}

class Comment extends Model {
@attr('string') text;
@belongsTo('post', { async: true }) post;
@belongsTo('post', { async: true, inverse: 'comments' }) post;
}

class Handle extends Model {
@belongsTo('user', { async: true }) user;
@belongsTo('user', { async: true, inverse: 'handles' }) user;
}

class GithubHandle extends Handle {
Expand All @@ -48,7 +48,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks)

class Company extends Model {
@attr('string') name;
@hasMany('user', { async: true }) employees;
@hasMany('user', { async: true, inverse: 'company' }) employees;
}

class DevelopmentShop extends Company {
Expand Down
Loading