How to use Ember Data with Nested Resources

前端 未结 1 1715
别那么骄傲
别那么骄傲 2021-01-18 01:57

My application backend has several resources. A model is exposed for each resource.

The entry point to all other resources is through the User model. Wh

相关标签:
1条回答
  • 2021-01-18 02:36

    The best way to handle it is with links. If you don't want to do it like that, it is far from supported, and difficult to hack in (the pipeline just doesn't easily pass the information around). Personally I'd recommend rolling your own adapter in that case (Ember without Ember Data).

    App.Foo = DS.Model.extend({
      name: DS.attr('string'),
      bars : DS.hasMany('bar', {async:true})
    });
    
    App.Bar = DS.Model.extend({
      foo: DS.belongsTo('foo'),
    });
    

    json:

    {
      id: 1,
      name: "bill",
      links: {
        bars: '/foo/1/bars'
      }
    }
    

    Example: http://emberjs.jsbin.com/OxIDiVU/971/edit

    0 讨论(0)
提交回复
热议问题