Skip to content

Commit

Permalink
deprecation: implement strict relationships (#8115)
Browse files Browse the repository at this point in the history
* prepare to enforce string ids

* cleanup missing relationship types

* deprecate missing types

* deprecate not passing the async flag

* implement inverse deprecation

* fix a lot of deprecations

* 100 tests to go

* 25 remain

* all dev tests passing

* cleanup

* fixup

* fix test
  • Loading branch information
runspired authored Aug 12, 2022
1 parent 8e6b742 commit b6b5722
Show file tree
Hide file tree
Showing 85 changed files with 2,898 additions and 2,646 deletions.
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

0 comments on commit b6b5722

Please sign in to comment.