如何在Ember.js中声明多态关系上的'type'键?

如何在Ember.js中声明多态关系上的'type'键?,ember.js,Ember.js,我正在尝试学习ember.js,但在尝试使用模拟数据的DS.FixtureAdapter时遇到了一个问题。每当我尝试访问商店时,我都会收到以下余烬错误: 处理路由时出错:练习断言失败:余烬数据需要一个数字或字符串来表示pictureExercises关系中的记录,但它找到了一个对象。如果这是多态关系,请指定类型键。如果这是嵌入关系,请包括DS.EmbeddedRecordsMixin*,并在序列化程序的attrs哈希中指定pictureExercises属性 查看ember inspector中

我正在尝试学习ember.js,但在尝试使用模拟数据的
DS.FixtureAdapter
时遇到了一个问题。每当我尝试访问商店时,我都会收到以下余烬错误:

处理路由时出错:练习断言失败:余烬数据需要一个数字或字符串来表示
pictureExercises
关系中的记录,但它找到了一个对象。如果这是多态关系,请指定
类型
键。如果这是嵌入关系,请包括
DS.EmbeddedRecordsMixin*
,并在序列化程序的attrs哈希中指定
pictureExercises
属性

查看ember inspector中的ember数据部分,我可以看到所有顶级练习数据都加载正确,而PictureExercises和VideoXercises没有加载

如何在Ember.js中声明多态关系上的
类型

我完全不知所措,任何帮助都将不胜感激谢谢您抽出时间。

//Create application store    
Gymbo.ApplicationAdapter = DS.FixtureAdapter;

//Set up models and relationships
    Gymbo.Exercise = DS.Model.extend({
        //id: DS.attr("number"), /*Ember will error if id is in model* /
        name: DS.attr("string"),
        description: DS.attr("string"),        
        pictureExercises: DS.hasMany("pictureExercise", {async: true }),
        videoExercises: DS.hasMany("videoExercise", { async: true }) 
    });


Gymbo.PictureExercise = DS.Model.extend({
        //id: DS.attr("number"),
        exerciseId: DS.attr("number"),       
        mimeType: DS.attr("string"),
        picFilePath: DS.attr("string"),
        picName: DS.attr("string"),
        exercise: DS.belongsTo("exercise")
    });

    Gymbo.VideoExercise = DS.Model.extend({
        //id: DS.attr("number"),
        exerciseId: DS.attr("number"),       
        videoName: DS.attr("string"),
        videoFilePath: DS.attr("string"),
        videoType: DS.attr("string"),
        exercise: DS.belongsTo("exercise")
    });

//UsersRoute
    Gymbo.ExercisesRoute = Ember.Route.extend({
        model: function () {
            return this.store.find("exercise");                      
        }
    });

//MOCK DATA
    Gymbo.Exercise.reopenClass({
        FIXTURES:
          [
            {
                "id": 101,
                "name": "Exercise 1",
                "description": "Description here",
                "pictureExercises": [
                    {
                        "id": 106,
                        "exerciseId": 101,                        
                        "mimeType": "PNG",
                        "picFilePath": "images\\strength",
                        "picName": "s001"                        
                    },
                    {
                        "id": 107,
                        "exerciseId": 101,                       
                        "mimeType": "JPG",
                        "picFilePath": "images\\strength",
                        "picName": s002
                    }
                ],
                "videoExercises": [
                    {
                        "id": 101,
                        "exerciseId": 101,                       
                        "videoName": "Test",
                        "videoFilePath": "Video\\strength",
                        "videoType": "mp4"
                    }
                ]
            },
            {
        "id": 102,
                //Data removed for brevity.....
            }
          ]
    });

您是否尝试过删除hasMany关系上的异步标志?它们告诉适配器在练习记录中使用ID而不是对象。然后,适配器将根据这些记录的ID发出单独的请求。对于FixtureAdapter来说,这在直觉上可能没有多大意义,但是如果这些是从远程API提供的大记录,那么这很有意义。是的,我尝试过删除它们,但没有效果,我得到了相同的错误。我希望使用fixture构建一个模拟站点,然后简单地交换到RESTAdapter。我想我现在无论如何都要试一试,看看这会不会有什么不同,我已经浪费了很多时间。如果我得到答案或一些工作代码,我会在这里发布。非常感谢您的意见。您找到解决方案了吗?我想做的另一件事是在适配器中将coalesceFindRequests设置为true。嗨,没有找到解决方案。开发经理即将拔掉Ember的插头。他的理由是它不适合生产,因为它的数据看起来不可靠,没有太多的支持,而且它是一个未经验证的产品。我有点同意,他不能冒险,尤其是因为我们队有棱角技巧。我花了一天时间制作了一个合理的模型,但失败了。如果我有时间,我会自己继续。非常感谢您做出的贡献,您上一个建议也不起作用。我希望你运气好,如果你使用余烬数据,我真的很喜欢使用余烬。如果我找到答案,我会发帖的。