How to use multiple models with a single route in EmberJS / Ember Data?

前端 未结 8 2041
一整个雨季
一整个雨季 2020-11-27 09:16

From reading the docs, it looks like you have to (or should) assign a model to a route like so:

App.PostRoute = Ember.Route.extend({
    model: function() {
         


        
8条回答
  •  情话喂你
    2020-11-27 09:54

    Adding to MilkyWayJoe's answer, thanks btw:

    this.store.find('post',1) 
    

    returns

    {
        id: 1,
        title: 'string',
        body: 'string string string string...',
        author_id: 1,
        comment_ids: [1, 2, 3, 6],
        tag_ids: [3,4]
    };
    

    author would be

    {
        id: 1,
        firstName: 'Joe',
        lastName: 'Way',
        email: 'MilkyWayJoe@example.com',
        points: 6181,
        post_ids: [1,2,3,...,n],
        comment_ids: [1,2,3,...,n],
    }
    

    comments

    {
        id:1,
        author_id:1,
        body:'some words and stuff...',
        post_id:1,
    }
    

    ... I believe the link backs are important so that the full relationship is established. Hope that helps someone.

提交回复
热议问题