How do I create a polymorphic 1:1 relationships wtih Ember Data fixtures?

a 夏天 提交于 2019-12-13 04:19:40

问题


Page has a polymorphic 1:1 relationship with a model called PageContent. PageContent has two subtypes (TextOnly and Video). I want to be able to able to do a findAll for "page" and get all of the content back. What am I doing wrong?

JSBin


回答1:


This seems to work: http://jsbin.com/names/1/edit

Only wrong thing I could see is the App.Page.FIXTURES.

It should be:

 App.Page.FIXTURES = [
  {
    id: 1,
    title: "Introduction",
    pageContent: 1,
    pageContentType: "textOnly"

  },{
    id: 2,
    title: "Summary",
    pageContent: 1,
    pageContentType: "Video"

  }
];

or

App.Page.FIXTURES = [
  {
    id: 1,
    title: "Introduction",
    pageContent: {
      id: 1,
      type: "textOnly"
    }
  },{
    id: 2,
    title: "Summary",
    pageContent: {
      id: 1,
      type: "Video"
    }
  }
];


来源:https://stackoverflow.com/questions/25352402/how-do-i-create-a-polymorphic-11-relationships-wtih-ember-data-fixtures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!