[ember-data] Model#eachRelationship fixes (#27278)

This commit is contained in:
Mike North
2018-07-15 12:17:42 -07:00
committed by Ryan Cavanaugh
parent 57ab455b32
commit 2beceb200e
2 changed files with 16 additions and 2 deletions
+2 -2
View File
@@ -526,7 +526,7 @@ declare module 'ember-data' {
* invoking the callback with the name of each relationship and its relationship
* descriptor.
*/
eachRelationship(callback: Function, binding: any): any;
eachRelationship(callback: (name: string, details: RelationshipMeta<this>) => void, binding?: any): any;
/**
* Represents the model's class name as a string. This can be used to look up the model's class name through
* `DS.Store`'s modelFor method.
@@ -577,7 +577,7 @@ declare module 'ember-data' {
* invoking the callback with the name of each relationship and its relationship
* descriptor.
*/
static eachRelationship(callback: Function, binding: any): any;
static eachRelationship<M extends Model = Model>(callback: (name: string, details: RelationshipMeta<M>) => void, binding?: any): any;
/**
* Given a callback, iterates over each of the types related to a model,
* invoking the callback with the related type's class. Each type will be
+14
View File
@@ -12,6 +12,20 @@ const Polymorphic = DS.Model.extend({
paymentMethods: DS.hasMany('payment-method', { polymorphic: true })
});
Polymorphic.eachRelationship(() => '');
Polymorphic.eachRelationship(() => '', {});
Polymorphic.eachRelationship((n, meta) => {
let s: string = n;
let m: 'belongsTo' | 'hasMany' = meta.kind;
});
let p = Polymorphic.create();
p.eachRelationship(() => '');
p.eachRelationship(() => '', {});
p.eachRelationship((n, meta) => {
let s: string = n;
let m: 'belongsTo' | 'hasMany' = meta.kind;
});
class Comment extends DS.Model {
author = DS.attr('string');
}