javascript - Ember data, relationships and JSON -


i have following json being returned api:

{ "project": [     {         "id": "1",         "name": "my first project",         "owned_by": "1",         "updated_at": {             "date": "2015-05-06 15:46:27.000000",             "timezone_type": 3,             "timezone": "europe/london"         },         "created_at": {             "date": "2015-05-06 15:46:27.000000",             "timezone_type": 3,             "timezone": "europe/london"         }     } ], "subscriptions": [     {         "id": "10",         "output": "hello world",         "project_id": "1",         "owned_by": "1",         "updated_at": {             "date": "2015-05-06 16:56:40.000000",             "timezone_type": 3,             "timezone": "europe/london"         },         "created_at": {             "date": "2015-05-06 16:56:40.000000",             "timezone_type": 3,             "timezone": "europe/london"         }     } ] } 

and have following models:

project.js

import ds 'ember-data';  export default ds.model.extend({     name: ds.attr('string'),     ownedby: ds.attr('string'),     subscriptions: ds.hasmany('subscription') }); 

subscription.js import ds 'ember-data';

 export default ds.model.extend({      input: ds.attr('string'),      projects: ds.belongsto('project'),  }); 

the data being returned api , can project details, can't seem data relationship. using ember inspector shows data in data tab when try , loop through data {{#each item in model.subscription}} nothing returned.

enter image description here

your project json doesnt have reference subscriptions. project json should have array of ids on it, each id relating subscription id.
example code below emberjs.com substituting project post , subscription comment in case

{   "post": {     "id": 1,     "title": "node not omakase",     "comments": [1, 2, 3]   },    "comments": [{     "id": 1,     "body": "but _lightweight_ omakase?"   },   {     "id": 2,     "body": "i 1 welcome our new omakase overlords"   },   {     "id": 3,     "body": "put me on fast track delicious dinner"   }] } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -