diff --git a/types/ember-data/index.d.ts b/types/ember-data/index.d.ts index ea3de94436..5e4fa4eb60 100644 --- a/types/ember-data/index.d.ts +++ b/types/ember-data/index.d.ts @@ -521,11 +521,11 @@ declare module 'ember-data' { /** * Get the reference for the specified belongsTo relationship. */ - belongsTo(name: keyof ModelRegistry): BelongsToReference; + belongsTo(name: RelationshipsFor): BelongsToReference; /** * Get the reference for the specified hasMany relationship. */ - hasMany(name: keyof ModelRegistry): HasManyReference; + hasMany(name: RelationshipsFor): HasManyReference; /** * Given a callback, iterates over each of the relationships in the model, * invoking the callback with the name of each relationship and its relationship diff --git a/types/ember-data/test/relationships.ts b/types/ember-data/test/relationships.ts index fb89d4410c..df43387bb4 100644 --- a/types/ember-data/test/relationships.ts +++ b/types/ember-data/test/relationships.ts @@ -16,17 +16,23 @@ class Comment extends DS.Model { author = DS.attr('string'); } +class Series extends DS.Model { + title = DS.attr('string'); +} + class RelationalPost extends DS.Model { title = DS.attr('string'); tag = DS.attr('string'); comments = DS.hasMany('comment', { async: true }); relatedPosts = DS.hasMany('post'); + series = DS.belongsTo('series'); } declare module 'ember-data' { interface ModelRegistry { 'relational-post': RelationalPost; comment: Comment; + series: Series; } } @@ -35,3 +41,6 @@ blogPost!.get('comments').then((comments) => { // now we can work with the comments let author: string = comments.get('firstObject')!.get('author'); }); + +blogPost!.hasMany('relatedPosts'); +blogPost!.belongsTo('series');