Ember-Data: How to use `DS.Adapter.findHasMany`

前端 未结 4 1879
栀梦
栀梦 2021-02-06 01:36

UPDATE

Note that this question applies to Ember Data pre-1.0 beta, the mechanism for loading relationships via URL has changed significantly post-1.0 beta!


4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 02:17

    Instead of an array of ids, the payload needs to contain "something else" than an array.

    In the case of the RESTAdapter, the returned JSON is like that:

    {blog: {id: 1, comments: [1, 2, 3]}
    

    If you want to handle manually/differently the association, you can return a JSON like that instead:

    {blog: {id: 1, comments: "/posts/1/comments"}
    

    It's up to your adapter then to fetch the data from the specified URL.

    See the associated test: https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/has_many_test.js#L112

提交回复
热议问题