Fix DS.Model.belongsTo and DS.Model.hasMany args (#25072)

This commit is contained in:
Abram Booth
2018-04-17 18:11:35 -07:00
committed by Ryan Cavanaugh
parent 8c3fdbcf02
commit 16c3ba2628
2 changed files with 11 additions and 2 deletions
+2 -2
View File
@@ -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
+9
View File
@@ -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');