代码之家  ›  专栏  ›  技术社区  ›  blueFast

将嵌入式对象与固定设备一起使用

  •  1
  • blueFast  · 技术社区  · 12 年前

    使用 REST Adapter ,可以通过执行以下操作来嵌入对象:

    App.Adapter.map('App.User', {
        properties : {embedded: 'always'},
    });
    

    如何使用声明嵌入对象 FIXTURE ? 我已尝试在模型中指定此项:

    App.User = DS.Model.extend({
        properties : DS.belongsTo('App.UserProperties', { embedded : true })
    });
    

    但这并不奏效。是否可以使用 FIXTURES ? 我的 固定装置 看起来像:

    App.User.FIXTURES = [
        { 
            id: 'id1',
            type: 'user', 
            properties : { 
                name: 'Max Smith',
                email: 'max.smith@email.com' }
        },
    ];
    
    1 回复  |  直到 12 年前
        1
  •  2
  •   intuitivepixel    12 年前

    这个 FixtureAdapter 不支持嵌入记录,唯一的方法是定义 FIXTURES 为了你 UserProperties 型号:

    App.User.FIXTURES = [
      { 
        id: 'id1',
        type: 'user', 
        properties : 1
    ];
    
    App.UserProperties.FIXTURES = [
      { 
        id: '1',
        name: 'Max Smith',
        email: 'max.smith@email.com'
      }
    ];
    

    这里还有@tomdale(ember数据的创建者之一)关于 固定件适配器

    我不认为fixture适配器支持嵌入式记录 有充分的理由说明为什么需要这样做吗? 它也不支持undercored_property_name fixture适配器的想法不是模仿来自服务器的JSON负载 它以Ember data期望的格式提供存根数据 因此关系不是嵌入的,属性名称是基于骆驼的,等等。

    希望能有所帮助。

    推荐文章