Skip to content
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
4 changes: 2 additions & 2 deletions types/ember-data/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,11 @@ declare module 'ember-data' {
/**
* Get the reference for the specified belongsTo relationship.
*/
belongsTo(name: keyof ModelRegistry): BelongsToReference;
belongsTo(name: RelationshipsFor<this>): BelongsToReference;
/**
* Get the reference for the specified hasMany relationship.
*/
hasMany(name: keyof ModelRegistry): HasManyReference<any>;
hasMany(name: RelationshipsFor<this>): HasManyReference<any>;
/**
* Given a callback, iterates over each of the relationships in the model,
* invoking the callback with the name of each relationship and its relationship
Expand Down
9 changes: 9 additions & 0 deletions types/ember-data/test/relationships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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');