如何使多态异步与ember-data有很多关系?

时间:2014-03-05 14:32:28

标签: ember.js ember-data

我正在将ember-data .13移植到最新的ember-data中,并且无法使多态hasMany关系正常工作。

我有一个模特人。一个人有很多帖子。帖子是多态的,所以有photoPosts,textPosts,......

应该在异步请求中加载帖子,但使多态性工作的唯一方法是通过旁加载任务。 (http://jsfiddle.net/koenig/3qwEP/7/

以下是我的模特

App.Post = DS.Model.extend({
    title: DS.attr('string'),
    person: DS.belongsTo('person') 
});

App.PhotoPost = App.Post.extend({
    photoUrl: DS.attr('string'),
    postType: 'photo' 
});

App.TextPost = App.Post.extend({
    body: DS.attr('string'),
    postType: 'text'
});

App.Person = DS.Model.extend({
    firstName: DS.attr('string'),
    lastName: DS.attr('string'),
    posts: DS.hasMany('post', {async: true, polymorphic: true}),

    fullName: function() {
        return this.get('firstName') + ' ' + this.get('lastName');
    }.property('firstName', 'lastName')
});

这是我的人员负载:

person: {
    id: 1, 
    first_name: 'luke', 
    last_name: 'skywalker', 
    links: { posts: '/people/1/posts' }
}

这适用于帖子:

posts: [ 
    {id: 1, title: 'A Photo', type: "photoPost" }, 
    {id: 2, title: 'Some Text', type: "textPost" }
]

我还尝试了不同的有效负载和变体,使用各种序列化程序挂钩,并在ember-data代码中查找答案。没有运气了。

我是否遗漏了某些内容,或者是在ember数据中无法实现的异步多态关系?

这是一个基本设置的jsfiddle:http://jsfiddle.net/koenig/3qwEP/

提前致谢。

0 个答案:

没有答案