Replace Ember.ArrayController.create() will not resolve belongTo relationships | ember upgrade 3.x












1














I'm in the process of upgrading and I'm facing issues because ArrayController is being deprecated.



In my old Ember 1.13 route I'm using



model/announcement.js



export default DS.Model.extend( {


id:DS.attr('string'),
title: DS.attr( 'string' ),
description: DS.attr( 'string' ),
published: DS.attr( 'boolean' ),
publishedAt: DS.attr( 'date' ),

course: DS.belongsTo( 'course' ),
author: DS.belongsTo( 'profile', { async: true } ),

viewed: false,
isNew: true,

}


serializer/announcement.js



import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {

keyForRelationship: function( key ) {

return key !== 'author' ? key : 'id';
}
} );


routes/announcement.js



 setupController: function( controller, model ) {

this._super( ...arguments );

var announcements = Ember.ArrayController.create( {

model: model,
sortProperties: [ 'publishedAt' ],
sortAscending: false
} );

controller.set( 'model', announcements );
},


In the controller of the route announcement, follows:



controller/announcement.js



publishedAnnouncements: Ember.computed( 'model.', 'model.@each.published', 'model.@each.viewed', function() {

var published = this.get( 'model' ).filterBy( 'published', true ),
announcements = Ember.A();

announcements.pushObjects( published.filterBy( 'viewed', false ) );
announcements.pushObjects( published.filterBy( 'viewed' ) );

return announcements;
} ),


so in the template im running a for each loop to render all announcements like



templates/announcements.hbs



  {{#each publishedAnnouncements as |announcement|}}
{{announcement.author.firstName}}
{{/each}}


After the ember upgrade 3.5 I have changed these to the following:



model/announcement.js



export default DS.Model.extend( {

id:DS.attr('string'),
title: DS.attr( 'string' ),
description: DS.attr( 'string' ),
published: DS.attr( 'boolean' ),
publishedAt: DS.attr( 'date' ),

course: DS.belongsTo( 'course' ),


// remove async true from profile



  author: DS.belongsTo( 'profile'),

viewed: false,
isNew: true,

}


serializer/announcement.js



import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {

keyForRelationship: function( key ) {

return key !== 'author' ? key : 'id';
}
} );


routes/announcement.js



setupController: function( controller, model ) {

this._super( ...arguments );

//removed arrayController from here and assigned model

controller.set( 'model', model );
},


controller/announcement.js



sortProperties: ['publishedAt:desc'],
sortedModel: computed.sort('model', 'sortProperties'),



publishedAnnouncements: Ember.computed( 'model.', 'model.@each.published', 'model.@each.viewed', function() {

//getting model by local computed property defined above.arrayController sort is doing with above method by sortPropteries
var published =this.get('sortedModel').filterBy( 'published', true);
announcements = Ember.A();

announcements.pushObjects( published.filterBy( 'viewed', false ) );
announcements.pushObjects( published.filterBy( 'viewed' ) );

return announcements;
} ),


templates/announcements.hbs



  {{#each publishedAnnouncements as |announcement|}}
{{announcement.author.firstName}}
{{/each}}


Then the announcement.author.firstname is undefined in ember 3.5
but if it is not a belongsTo relationship it will be there (example announcement.publishedAt)



I have no clue what I missed or what I did wrong here.



I am attaching a screenshot here of a console log which I did in the controller published variable.



Ember 1.13



enter image description here



Ember 3.5
enter image description here



your answers make me better understand the problem. the api returns a custom version of data thats why embeddedRecordsMixin used this is the api payload for course



{
"courses": [{
"created_at": "2016-11-22T09:37:53+00:00",
"updated_at": "2016-11-22T09:37:53+00:00",
"students": ["01", "02"],
"coordinators": ["001", "002"],
"programme_id": 1,
"announcements": [{
"created_at": "2016-11-23T08:27:31+00:00",
"updated_at": "2016-11-23T08:27:31+00:00",
"course_id": 099,
"id": 33,
"title": "test announcement",
"description": "please ignore",
"published_at": "2016-11-23T08:27:31+00:00",
"published": true
}, {
"created_at": "2016-11-25T07:13:18+00:00",
"updated_at": "2016-11-25T07:13:18+00:00",
"course_id": 04,
"id": 22,
"title": "test before ",
"description": "test",
"published_at": "2016-11-25T07:13:18+00:00",
"published": true
}]
}









share|improve this question




















  • 1




    Does your API return JSON API compliant JSON? jsonapi.org
    – Jan Werkhoven
    Nov 12 '18 at 6:16








  • 1




    What's keyForRelationship in the announcement serialiser needed for? That seems out of place.
    – Jan Werkhoven
    Nov 12 '18 at 6:19






  • 1




    It's quite unusual to be using setupController. If you follow the naming conventions, it should be obsolete.
    – Jan Werkhoven
    Nov 12 '18 at 6:21










  • cause api doesn't give author key so there is a map to profile where announcement's id is the key of profile
    – Thilina Dinith Fonseka
    Nov 12 '18 at 6:21






  • 1




    Can you add models/author.js as well?
    – Jan Werkhoven
    Nov 12 '18 at 6:31
















1














I'm in the process of upgrading and I'm facing issues because ArrayController is being deprecated.



In my old Ember 1.13 route I'm using



model/announcement.js



export default DS.Model.extend( {


id:DS.attr('string'),
title: DS.attr( 'string' ),
description: DS.attr( 'string' ),
published: DS.attr( 'boolean' ),
publishedAt: DS.attr( 'date' ),

course: DS.belongsTo( 'course' ),
author: DS.belongsTo( 'profile', { async: true } ),

viewed: false,
isNew: true,

}


serializer/announcement.js



import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {

keyForRelationship: function( key ) {

return key !== 'author' ? key : 'id';
}
} );


routes/announcement.js



 setupController: function( controller, model ) {

this._super( ...arguments );

var announcements = Ember.ArrayController.create( {

model: model,
sortProperties: [ 'publishedAt' ],
sortAscending: false
} );

controller.set( 'model', announcements );
},


In the controller of the route announcement, follows:



controller/announcement.js



publishedAnnouncements: Ember.computed( 'model.', 'model.@each.published', 'model.@each.viewed', function() {

var published = this.get( 'model' ).filterBy( 'published', true ),
announcements = Ember.A();

announcements.pushObjects( published.filterBy( 'viewed', false ) );
announcements.pushObjects( published.filterBy( 'viewed' ) );

return announcements;
} ),


so in the template im running a for each loop to render all announcements like



templates/announcements.hbs



  {{#each publishedAnnouncements as |announcement|}}
{{announcement.author.firstName}}
{{/each}}


After the ember upgrade 3.5 I have changed these to the following:



model/announcement.js



export default DS.Model.extend( {

id:DS.attr('string'),
title: DS.attr( 'string' ),
description: DS.attr( 'string' ),
published: DS.attr( 'boolean' ),
publishedAt: DS.attr( 'date' ),

course: DS.belongsTo( 'course' ),


// remove async true from profile



  author: DS.belongsTo( 'profile'),

viewed: false,
isNew: true,

}


serializer/announcement.js



import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {

keyForRelationship: function( key ) {

return key !== 'author' ? key : 'id';
}
} );


routes/announcement.js



setupController: function( controller, model ) {

this._super( ...arguments );

//removed arrayController from here and assigned model

controller.set( 'model', model );
},


controller/announcement.js



sortProperties: ['publishedAt:desc'],
sortedModel: computed.sort('model', 'sortProperties'),



publishedAnnouncements: Ember.computed( 'model.', 'model.@each.published', 'model.@each.viewed', function() {

//getting model by local computed property defined above.arrayController sort is doing with above method by sortPropteries
var published =this.get('sortedModel').filterBy( 'published', true);
announcements = Ember.A();

announcements.pushObjects( published.filterBy( 'viewed', false ) );
announcements.pushObjects( published.filterBy( 'viewed' ) );

return announcements;
} ),


templates/announcements.hbs



  {{#each publishedAnnouncements as |announcement|}}
{{announcement.author.firstName}}
{{/each}}


Then the announcement.author.firstname is undefined in ember 3.5
but if it is not a belongsTo relationship it will be there (example announcement.publishedAt)



I have no clue what I missed or what I did wrong here.



I am attaching a screenshot here of a console log which I did in the controller published variable.



Ember 1.13



enter image description here



Ember 3.5
enter image description here



your answers make me better understand the problem. the api returns a custom version of data thats why embeddedRecordsMixin used this is the api payload for course



{
"courses": [{
"created_at": "2016-11-22T09:37:53+00:00",
"updated_at": "2016-11-22T09:37:53+00:00",
"students": ["01", "02"],
"coordinators": ["001", "002"],
"programme_id": 1,
"announcements": [{
"created_at": "2016-11-23T08:27:31+00:00",
"updated_at": "2016-11-23T08:27:31+00:00",
"course_id": 099,
"id": 33,
"title": "test announcement",
"description": "please ignore",
"published_at": "2016-11-23T08:27:31+00:00",
"published": true
}, {
"created_at": "2016-11-25T07:13:18+00:00",
"updated_at": "2016-11-25T07:13:18+00:00",
"course_id": 04,
"id": 22,
"title": "test before ",
"description": "test",
"published_at": "2016-11-25T07:13:18+00:00",
"published": true
}]
}









share|improve this question




















  • 1




    Does your API return JSON API compliant JSON? jsonapi.org
    – Jan Werkhoven
    Nov 12 '18 at 6:16








  • 1




    What's keyForRelationship in the announcement serialiser needed for? That seems out of place.
    – Jan Werkhoven
    Nov 12 '18 at 6:19






  • 1




    It's quite unusual to be using setupController. If you follow the naming conventions, it should be obsolete.
    – Jan Werkhoven
    Nov 12 '18 at 6:21










  • cause api doesn't give author key so there is a map to profile where announcement's id is the key of profile
    – Thilina Dinith Fonseka
    Nov 12 '18 at 6:21






  • 1




    Can you add models/author.js as well?
    – Jan Werkhoven
    Nov 12 '18 at 6:31














1












1








1







I'm in the process of upgrading and I'm facing issues because ArrayController is being deprecated.



In my old Ember 1.13 route I'm using



model/announcement.js



export default DS.Model.extend( {


id:DS.attr('string'),
title: DS.attr( 'string' ),
description: DS.attr( 'string' ),
published: DS.attr( 'boolean' ),
publishedAt: DS.attr( 'date' ),

course: DS.belongsTo( 'course' ),
author: DS.belongsTo( 'profile', { async: true } ),

viewed: false,
isNew: true,

}


serializer/announcement.js



import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {

keyForRelationship: function( key ) {

return key !== 'author' ? key : 'id';
}
} );


routes/announcement.js



 setupController: function( controller, model ) {

this._super( ...arguments );

var announcements = Ember.ArrayController.create( {

model: model,
sortProperties: [ 'publishedAt' ],
sortAscending: false
} );

controller.set( 'model', announcements );
},


In the controller of the route announcement, follows:



controller/announcement.js



publishedAnnouncements: Ember.computed( 'model.', 'model.@each.published', 'model.@each.viewed', function() {

var published = this.get( 'model' ).filterBy( 'published', true ),
announcements = Ember.A();

announcements.pushObjects( published.filterBy( 'viewed', false ) );
announcements.pushObjects( published.filterBy( 'viewed' ) );

return announcements;
} ),


so in the template im running a for each loop to render all announcements like



templates/announcements.hbs



  {{#each publishedAnnouncements as |announcement|}}
{{announcement.author.firstName}}
{{/each}}


After the ember upgrade 3.5 I have changed these to the following:



model/announcement.js



export default DS.Model.extend( {

id:DS.attr('string'),
title: DS.attr( 'string' ),
description: DS.attr( 'string' ),
published: DS.attr( 'boolean' ),
publishedAt: DS.attr( 'date' ),

course: DS.belongsTo( 'course' ),


// remove async true from profile



  author: DS.belongsTo( 'profile'),

viewed: false,
isNew: true,

}


serializer/announcement.js



import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {

keyForRelationship: function( key ) {

return key !== 'author' ? key : 'id';
}
} );


routes/announcement.js



setupController: function( controller, model ) {

this._super( ...arguments );

//removed arrayController from here and assigned model

controller.set( 'model', model );
},


controller/announcement.js



sortProperties: ['publishedAt:desc'],
sortedModel: computed.sort('model', 'sortProperties'),



publishedAnnouncements: Ember.computed( 'model.', 'model.@each.published', 'model.@each.viewed', function() {

//getting model by local computed property defined above.arrayController sort is doing with above method by sortPropteries
var published =this.get('sortedModel').filterBy( 'published', true);
announcements = Ember.A();

announcements.pushObjects( published.filterBy( 'viewed', false ) );
announcements.pushObjects( published.filterBy( 'viewed' ) );

return announcements;
} ),


templates/announcements.hbs



  {{#each publishedAnnouncements as |announcement|}}
{{announcement.author.firstName}}
{{/each}}


Then the announcement.author.firstname is undefined in ember 3.5
but if it is not a belongsTo relationship it will be there (example announcement.publishedAt)



I have no clue what I missed or what I did wrong here.



I am attaching a screenshot here of a console log which I did in the controller published variable.



Ember 1.13



enter image description here



Ember 3.5
enter image description here



your answers make me better understand the problem. the api returns a custom version of data thats why embeddedRecordsMixin used this is the api payload for course



{
"courses": [{
"created_at": "2016-11-22T09:37:53+00:00",
"updated_at": "2016-11-22T09:37:53+00:00",
"students": ["01", "02"],
"coordinators": ["001", "002"],
"programme_id": 1,
"announcements": [{
"created_at": "2016-11-23T08:27:31+00:00",
"updated_at": "2016-11-23T08:27:31+00:00",
"course_id": 099,
"id": 33,
"title": "test announcement",
"description": "please ignore",
"published_at": "2016-11-23T08:27:31+00:00",
"published": true
}, {
"created_at": "2016-11-25T07:13:18+00:00",
"updated_at": "2016-11-25T07:13:18+00:00",
"course_id": 04,
"id": 22,
"title": "test before ",
"description": "test",
"published_at": "2016-11-25T07:13:18+00:00",
"published": true
}]
}









share|improve this question















I'm in the process of upgrading and I'm facing issues because ArrayController is being deprecated.



In my old Ember 1.13 route I'm using



model/announcement.js



export default DS.Model.extend( {


id:DS.attr('string'),
title: DS.attr( 'string' ),
description: DS.attr( 'string' ),
published: DS.attr( 'boolean' ),
publishedAt: DS.attr( 'date' ),

course: DS.belongsTo( 'course' ),
author: DS.belongsTo( 'profile', { async: true } ),

viewed: false,
isNew: true,

}


serializer/announcement.js



import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {

keyForRelationship: function( key ) {

return key !== 'author' ? key : 'id';
}
} );


routes/announcement.js



 setupController: function( controller, model ) {

this._super( ...arguments );

var announcements = Ember.ArrayController.create( {

model: model,
sortProperties: [ 'publishedAt' ],
sortAscending: false
} );

controller.set( 'model', announcements );
},


In the controller of the route announcement, follows:



controller/announcement.js



publishedAnnouncements: Ember.computed( 'model.', 'model.@each.published', 'model.@each.viewed', function() {

var published = this.get( 'model' ).filterBy( 'published', true ),
announcements = Ember.A();

announcements.pushObjects( published.filterBy( 'viewed', false ) );
announcements.pushObjects( published.filterBy( 'viewed' ) );

return announcements;
} ),


so in the template im running a for each loop to render all announcements like



templates/announcements.hbs



  {{#each publishedAnnouncements as |announcement|}}
{{announcement.author.firstName}}
{{/each}}


After the ember upgrade 3.5 I have changed these to the following:



model/announcement.js



export default DS.Model.extend( {

id:DS.attr('string'),
title: DS.attr( 'string' ),
description: DS.attr( 'string' ),
published: DS.attr( 'boolean' ),
publishedAt: DS.attr( 'date' ),

course: DS.belongsTo( 'course' ),


// remove async true from profile



  author: DS.belongsTo( 'profile'),

viewed: false,
isNew: true,

}


serializer/announcement.js



import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {

keyForRelationship: function( key ) {

return key !== 'author' ? key : 'id';
}
} );


routes/announcement.js



setupController: function( controller, model ) {

this._super( ...arguments );

//removed arrayController from here and assigned model

controller.set( 'model', model );
},


controller/announcement.js



sortProperties: ['publishedAt:desc'],
sortedModel: computed.sort('model', 'sortProperties'),



publishedAnnouncements: Ember.computed( 'model.', 'model.@each.published', 'model.@each.viewed', function() {

//getting model by local computed property defined above.arrayController sort is doing with above method by sortPropteries
var published =this.get('sortedModel').filterBy( 'published', true);
announcements = Ember.A();

announcements.pushObjects( published.filterBy( 'viewed', false ) );
announcements.pushObjects( published.filterBy( 'viewed' ) );

return announcements;
} ),


templates/announcements.hbs



  {{#each publishedAnnouncements as |announcement|}}
{{announcement.author.firstName}}
{{/each}}


Then the announcement.author.firstname is undefined in ember 3.5
but if it is not a belongsTo relationship it will be there (example announcement.publishedAt)



I have no clue what I missed or what I did wrong here.



I am attaching a screenshot here of a console log which I did in the controller published variable.



Ember 1.13



enter image description here



Ember 3.5
enter image description here



your answers make me better understand the problem. the api returns a custom version of data thats why embeddedRecordsMixin used this is the api payload for course



{
"courses": [{
"created_at": "2016-11-22T09:37:53+00:00",
"updated_at": "2016-11-22T09:37:53+00:00",
"students": ["01", "02"],
"coordinators": ["001", "002"],
"programme_id": 1,
"announcements": [{
"created_at": "2016-11-23T08:27:31+00:00",
"updated_at": "2016-11-23T08:27:31+00:00",
"course_id": 099,
"id": 33,
"title": "test announcement",
"description": "please ignore",
"published_at": "2016-11-23T08:27:31+00:00",
"published": true
}, {
"created_at": "2016-11-25T07:13:18+00:00",
"updated_at": "2016-11-25T07:13:18+00:00",
"course_id": 04,
"id": 22,
"title": "test before ",
"description": "test",
"published_at": "2016-11-25T07:13:18+00:00",
"published": true
}]
}






javascript ember.js ember-data ember-router ember-controllers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 1:43

























asked Nov 12 '18 at 4:00









Thilina Dinith Fonseka

86113




86113








  • 1




    Does your API return JSON API compliant JSON? jsonapi.org
    – Jan Werkhoven
    Nov 12 '18 at 6:16








  • 1




    What's keyForRelationship in the announcement serialiser needed for? That seems out of place.
    – Jan Werkhoven
    Nov 12 '18 at 6:19






  • 1




    It's quite unusual to be using setupController. If you follow the naming conventions, it should be obsolete.
    – Jan Werkhoven
    Nov 12 '18 at 6:21










  • cause api doesn't give author key so there is a map to profile where announcement's id is the key of profile
    – Thilina Dinith Fonseka
    Nov 12 '18 at 6:21






  • 1




    Can you add models/author.js as well?
    – Jan Werkhoven
    Nov 12 '18 at 6:31














  • 1




    Does your API return JSON API compliant JSON? jsonapi.org
    – Jan Werkhoven
    Nov 12 '18 at 6:16








  • 1




    What's keyForRelationship in the announcement serialiser needed for? That seems out of place.
    – Jan Werkhoven
    Nov 12 '18 at 6:19






  • 1




    It's quite unusual to be using setupController. If you follow the naming conventions, it should be obsolete.
    – Jan Werkhoven
    Nov 12 '18 at 6:21










  • cause api doesn't give author key so there is a map to profile where announcement's id is the key of profile
    – Thilina Dinith Fonseka
    Nov 12 '18 at 6:21






  • 1




    Can you add models/author.js as well?
    – Jan Werkhoven
    Nov 12 '18 at 6:31








1




1




Does your API return JSON API compliant JSON? jsonapi.org
– Jan Werkhoven
Nov 12 '18 at 6:16






Does your API return JSON API compliant JSON? jsonapi.org
– Jan Werkhoven
Nov 12 '18 at 6:16






1




1




What's keyForRelationship in the announcement serialiser needed for? That seems out of place.
– Jan Werkhoven
Nov 12 '18 at 6:19




What's keyForRelationship in the announcement serialiser needed for? That seems out of place.
– Jan Werkhoven
Nov 12 '18 at 6:19




1




1




It's quite unusual to be using setupController. If you follow the naming conventions, it should be obsolete.
– Jan Werkhoven
Nov 12 '18 at 6:21




It's quite unusual to be using setupController. If you follow the naming conventions, it should be obsolete.
– Jan Werkhoven
Nov 12 '18 at 6:21












cause api doesn't give author key so there is a map to profile where announcement's id is the key of profile
– Thilina Dinith Fonseka
Nov 12 '18 at 6:21




cause api doesn't give author key so there is a map to profile where announcement's id is the key of profile
– Thilina Dinith Fonseka
Nov 12 '18 at 6:21




1




1




Can you add models/author.js as well?
– Jan Werkhoven
Nov 12 '18 at 6:31




Can you add models/author.js as well?
– Jan Werkhoven
Nov 12 '18 at 6:31












2 Answers
2






active

oldest

votes


















1














Where to start debugging:



Have a look at what your API returns:




  1. Spin up your local Ember app and API.

  2. Open localhost:4200 in Chrome.

  3. Open the network tab in dev tools.

  4. Refresh the page to trigger the network request I assume is in your route's model() hook.

  5. Look at the JSON returned by your API. Is it JSON API compliant?

  6. Open the data tab in Ember Inspector.

  7. After the request occurred, did the author you are expecting to see populate the store?

  8. If yes, does he have firstName or is it undefined?


If all positive, then we can probably rule out issues with the request, API and serialisers.



Seeing this serializer:



// app/serializers/announcments.js

import DS from 'ember-data';
import ApplicationSerializer from 'mim/serializers/application';

export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {
keyForRelationship: function( key ) {
return key !== 'author' ? key : 'id';
}
} );


The mixin EmbeddedRecordsMixin implies your API returns embedded data which is quite uncommon for JSON API compliant responses. This is the only serializer you will need if all according this spec:



// app/serializers/application.js

import JSONAPISerializer from 'ember-data/serializers/json-api';

export default JSONAPISerializer.extend({});


The data coming from your API should be looking like:



{
"data": [{
"type": "announcement",
"id": "1",
"attributes": {
"message": "...",
},
"relationships": {
"author": {
"data": { "type": "profile", "id": "9" }
},
}
}],
"included": [{
"type": "profile",
"id": "9",
"attributes": {
"firstName": "John",
"lastName": "Johnson"
},
}]
}





share|improve this answer























  • let me tell you the relationships actually the announcement data is coming as follow -> 'programme has courses. course has announcements. announcement has profiles ( this profile is mapped with author using belongsTo ) .' 5. yes its JSON API compliant but in announcement api doenst give author details cause its mapped using profile 7. there is no author cause im using author as profile in store
    – Thilina Dinith Fonseka
    Nov 12 '18 at 6:38








  • 1




    Have you opened Ember Inspector and looked at the Data tab? Did the profile of the author successfully load into the store?
    – Jan Werkhoven
    Nov 12 '18 at 6:43






  • 1




    So the issue is most likely the serializers. These are responsible for interpreting the JSON the API sent and then populates the Ember Data store. If this is done well, then you will see this in Ember Inspector. Given that we do not see data there, have a look at the JSON your API sent back. Do this by opening the network tab of Chrome dev tools, find the request and open the preview tab.
    – Jan Werkhoven
    Nov 12 '18 at 6:56






  • 1




    i was missing the author entity from backend api and after fixing that it worked perfectly. thanks for your help and time to resolve this issue. much appreciated !
    – Thilina Dinith Fonseka
    Nov 27 '18 at 3:18






  • 1




    You are most welcome :)
    – Jan Werkhoven
    Nov 27 '18 at 5:01



















1














Ember is designed to be back-end agnostic. With the serialisers you can convert all JSON from incoming server responses to suit the Ember Data store. Similarily you use adapters to convert outgoing server requests to suit your back-end.



I recommend reading this doc:



https://guides.emberjs.com/release/models/customizing-serializers/



Then choose from:





  • JSON API
    serializers (recommended)

  • REST
    serializers

  • Active Model serializers

  • Create your own custom
    serializer

  • Embedded records mixin






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255803%2freplace-ember-arraycontroller-create-will-not-resolve-belongto-relationships%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Where to start debugging:



    Have a look at what your API returns:




    1. Spin up your local Ember app and API.

    2. Open localhost:4200 in Chrome.

    3. Open the network tab in dev tools.

    4. Refresh the page to trigger the network request I assume is in your route's model() hook.

    5. Look at the JSON returned by your API. Is it JSON API compliant?

    6. Open the data tab in Ember Inspector.

    7. After the request occurred, did the author you are expecting to see populate the store?

    8. If yes, does he have firstName or is it undefined?


    If all positive, then we can probably rule out issues with the request, API and serialisers.



    Seeing this serializer:



    // app/serializers/announcments.js

    import DS from 'ember-data';
    import ApplicationSerializer from 'mim/serializers/application';

    export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {
    keyForRelationship: function( key ) {
    return key !== 'author' ? key : 'id';
    }
    } );


    The mixin EmbeddedRecordsMixin implies your API returns embedded data which is quite uncommon for JSON API compliant responses. This is the only serializer you will need if all according this spec:



    // app/serializers/application.js

    import JSONAPISerializer from 'ember-data/serializers/json-api';

    export default JSONAPISerializer.extend({});


    The data coming from your API should be looking like:



    {
    "data": [{
    "type": "announcement",
    "id": "1",
    "attributes": {
    "message": "...",
    },
    "relationships": {
    "author": {
    "data": { "type": "profile", "id": "9" }
    },
    }
    }],
    "included": [{
    "type": "profile",
    "id": "9",
    "attributes": {
    "firstName": "John",
    "lastName": "Johnson"
    },
    }]
    }





    share|improve this answer























    • let me tell you the relationships actually the announcement data is coming as follow -> 'programme has courses. course has announcements. announcement has profiles ( this profile is mapped with author using belongsTo ) .' 5. yes its JSON API compliant but in announcement api doenst give author details cause its mapped using profile 7. there is no author cause im using author as profile in store
      – Thilina Dinith Fonseka
      Nov 12 '18 at 6:38








    • 1




      Have you opened Ember Inspector and looked at the Data tab? Did the profile of the author successfully load into the store?
      – Jan Werkhoven
      Nov 12 '18 at 6:43






    • 1




      So the issue is most likely the serializers. These are responsible for interpreting the JSON the API sent and then populates the Ember Data store. If this is done well, then you will see this in Ember Inspector. Given that we do not see data there, have a look at the JSON your API sent back. Do this by opening the network tab of Chrome dev tools, find the request and open the preview tab.
      – Jan Werkhoven
      Nov 12 '18 at 6:56






    • 1




      i was missing the author entity from backend api and after fixing that it worked perfectly. thanks for your help and time to resolve this issue. much appreciated !
      – Thilina Dinith Fonseka
      Nov 27 '18 at 3:18






    • 1




      You are most welcome :)
      – Jan Werkhoven
      Nov 27 '18 at 5:01
















    1














    Where to start debugging:



    Have a look at what your API returns:




    1. Spin up your local Ember app and API.

    2. Open localhost:4200 in Chrome.

    3. Open the network tab in dev tools.

    4. Refresh the page to trigger the network request I assume is in your route's model() hook.

    5. Look at the JSON returned by your API. Is it JSON API compliant?

    6. Open the data tab in Ember Inspector.

    7. After the request occurred, did the author you are expecting to see populate the store?

    8. If yes, does he have firstName or is it undefined?


    If all positive, then we can probably rule out issues with the request, API and serialisers.



    Seeing this serializer:



    // app/serializers/announcments.js

    import DS from 'ember-data';
    import ApplicationSerializer from 'mim/serializers/application';

    export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {
    keyForRelationship: function( key ) {
    return key !== 'author' ? key : 'id';
    }
    } );


    The mixin EmbeddedRecordsMixin implies your API returns embedded data which is quite uncommon for JSON API compliant responses. This is the only serializer you will need if all according this spec:



    // app/serializers/application.js

    import JSONAPISerializer from 'ember-data/serializers/json-api';

    export default JSONAPISerializer.extend({});


    The data coming from your API should be looking like:



    {
    "data": [{
    "type": "announcement",
    "id": "1",
    "attributes": {
    "message": "...",
    },
    "relationships": {
    "author": {
    "data": { "type": "profile", "id": "9" }
    },
    }
    }],
    "included": [{
    "type": "profile",
    "id": "9",
    "attributes": {
    "firstName": "John",
    "lastName": "Johnson"
    },
    }]
    }





    share|improve this answer























    • let me tell you the relationships actually the announcement data is coming as follow -> 'programme has courses. course has announcements. announcement has profiles ( this profile is mapped with author using belongsTo ) .' 5. yes its JSON API compliant but in announcement api doenst give author details cause its mapped using profile 7. there is no author cause im using author as profile in store
      – Thilina Dinith Fonseka
      Nov 12 '18 at 6:38








    • 1




      Have you opened Ember Inspector and looked at the Data tab? Did the profile of the author successfully load into the store?
      – Jan Werkhoven
      Nov 12 '18 at 6:43






    • 1




      So the issue is most likely the serializers. These are responsible for interpreting the JSON the API sent and then populates the Ember Data store. If this is done well, then you will see this in Ember Inspector. Given that we do not see data there, have a look at the JSON your API sent back. Do this by opening the network tab of Chrome dev tools, find the request and open the preview tab.
      – Jan Werkhoven
      Nov 12 '18 at 6:56






    • 1




      i was missing the author entity from backend api and after fixing that it worked perfectly. thanks for your help and time to resolve this issue. much appreciated !
      – Thilina Dinith Fonseka
      Nov 27 '18 at 3:18






    • 1




      You are most welcome :)
      – Jan Werkhoven
      Nov 27 '18 at 5:01














    1












    1








    1






    Where to start debugging:



    Have a look at what your API returns:




    1. Spin up your local Ember app and API.

    2. Open localhost:4200 in Chrome.

    3. Open the network tab in dev tools.

    4. Refresh the page to trigger the network request I assume is in your route's model() hook.

    5. Look at the JSON returned by your API. Is it JSON API compliant?

    6. Open the data tab in Ember Inspector.

    7. After the request occurred, did the author you are expecting to see populate the store?

    8. If yes, does he have firstName or is it undefined?


    If all positive, then we can probably rule out issues with the request, API and serialisers.



    Seeing this serializer:



    // app/serializers/announcments.js

    import DS from 'ember-data';
    import ApplicationSerializer from 'mim/serializers/application';

    export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {
    keyForRelationship: function( key ) {
    return key !== 'author' ? key : 'id';
    }
    } );


    The mixin EmbeddedRecordsMixin implies your API returns embedded data which is quite uncommon for JSON API compliant responses. This is the only serializer you will need if all according this spec:



    // app/serializers/application.js

    import JSONAPISerializer from 'ember-data/serializers/json-api';

    export default JSONAPISerializer.extend({});


    The data coming from your API should be looking like:



    {
    "data": [{
    "type": "announcement",
    "id": "1",
    "attributes": {
    "message": "...",
    },
    "relationships": {
    "author": {
    "data": { "type": "profile", "id": "9" }
    },
    }
    }],
    "included": [{
    "type": "profile",
    "id": "9",
    "attributes": {
    "firstName": "John",
    "lastName": "Johnson"
    },
    }]
    }





    share|improve this answer














    Where to start debugging:



    Have a look at what your API returns:




    1. Spin up your local Ember app and API.

    2. Open localhost:4200 in Chrome.

    3. Open the network tab in dev tools.

    4. Refresh the page to trigger the network request I assume is in your route's model() hook.

    5. Look at the JSON returned by your API. Is it JSON API compliant?

    6. Open the data tab in Ember Inspector.

    7. After the request occurred, did the author you are expecting to see populate the store?

    8. If yes, does he have firstName or is it undefined?


    If all positive, then we can probably rule out issues with the request, API and serialisers.



    Seeing this serializer:



    // app/serializers/announcments.js

    import DS from 'ember-data';
    import ApplicationSerializer from 'mim/serializers/application';

    export default ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {
    keyForRelationship: function( key ) {
    return key !== 'author' ? key : 'id';
    }
    } );


    The mixin EmbeddedRecordsMixin implies your API returns embedded data which is quite uncommon for JSON API compliant responses. This is the only serializer you will need if all according this spec:



    // app/serializers/application.js

    import JSONAPISerializer from 'ember-data/serializers/json-api';

    export default JSONAPISerializer.extend({});


    The data coming from your API should be looking like:



    {
    "data": [{
    "type": "announcement",
    "id": "1",
    "attributes": {
    "message": "...",
    },
    "relationships": {
    "author": {
    "data": { "type": "profile", "id": "9" }
    },
    }
    }],
    "included": [{
    "type": "profile",
    "id": "9",
    "attributes": {
    "firstName": "John",
    "lastName": "Johnson"
    },
    }]
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 12 '18 at 6:52

























    answered Nov 12 '18 at 6:28









    Jan Werkhoven

    1,5721425




    1,5721425












    • let me tell you the relationships actually the announcement data is coming as follow -> 'programme has courses. course has announcements. announcement has profiles ( this profile is mapped with author using belongsTo ) .' 5. yes its JSON API compliant but in announcement api doenst give author details cause its mapped using profile 7. there is no author cause im using author as profile in store
      – Thilina Dinith Fonseka
      Nov 12 '18 at 6:38








    • 1




      Have you opened Ember Inspector and looked at the Data tab? Did the profile of the author successfully load into the store?
      – Jan Werkhoven
      Nov 12 '18 at 6:43






    • 1




      So the issue is most likely the serializers. These are responsible for interpreting the JSON the API sent and then populates the Ember Data store. If this is done well, then you will see this in Ember Inspector. Given that we do not see data there, have a look at the JSON your API sent back. Do this by opening the network tab of Chrome dev tools, find the request and open the preview tab.
      – Jan Werkhoven
      Nov 12 '18 at 6:56






    • 1




      i was missing the author entity from backend api and after fixing that it worked perfectly. thanks for your help and time to resolve this issue. much appreciated !
      – Thilina Dinith Fonseka
      Nov 27 '18 at 3:18






    • 1




      You are most welcome :)
      – Jan Werkhoven
      Nov 27 '18 at 5:01


















    • let me tell you the relationships actually the announcement data is coming as follow -> 'programme has courses. course has announcements. announcement has profiles ( this profile is mapped with author using belongsTo ) .' 5. yes its JSON API compliant but in announcement api doenst give author details cause its mapped using profile 7. there is no author cause im using author as profile in store
      – Thilina Dinith Fonseka
      Nov 12 '18 at 6:38








    • 1




      Have you opened Ember Inspector and looked at the Data tab? Did the profile of the author successfully load into the store?
      – Jan Werkhoven
      Nov 12 '18 at 6:43






    • 1




      So the issue is most likely the serializers. These are responsible for interpreting the JSON the API sent and then populates the Ember Data store. If this is done well, then you will see this in Ember Inspector. Given that we do not see data there, have a look at the JSON your API sent back. Do this by opening the network tab of Chrome dev tools, find the request and open the preview tab.
      – Jan Werkhoven
      Nov 12 '18 at 6:56






    • 1




      i was missing the author entity from backend api and after fixing that it worked perfectly. thanks for your help and time to resolve this issue. much appreciated !
      – Thilina Dinith Fonseka
      Nov 27 '18 at 3:18






    • 1




      You are most welcome :)
      – Jan Werkhoven
      Nov 27 '18 at 5:01
















    let me tell you the relationships actually the announcement data is coming as follow -> 'programme has courses. course has announcements. announcement has profiles ( this profile is mapped with author using belongsTo ) .' 5. yes its JSON API compliant but in announcement api doenst give author details cause its mapped using profile 7. there is no author cause im using author as profile in store
    – Thilina Dinith Fonseka
    Nov 12 '18 at 6:38






    let me tell you the relationships actually the announcement data is coming as follow -> 'programme has courses. course has announcements. announcement has profiles ( this profile is mapped with author using belongsTo ) .' 5. yes its JSON API compliant but in announcement api doenst give author details cause its mapped using profile 7. there is no author cause im using author as profile in store
    – Thilina Dinith Fonseka
    Nov 12 '18 at 6:38






    1




    1




    Have you opened Ember Inspector and looked at the Data tab? Did the profile of the author successfully load into the store?
    – Jan Werkhoven
    Nov 12 '18 at 6:43




    Have you opened Ember Inspector and looked at the Data tab? Did the profile of the author successfully load into the store?
    – Jan Werkhoven
    Nov 12 '18 at 6:43




    1




    1




    So the issue is most likely the serializers. These are responsible for interpreting the JSON the API sent and then populates the Ember Data store. If this is done well, then you will see this in Ember Inspector. Given that we do not see data there, have a look at the JSON your API sent back. Do this by opening the network tab of Chrome dev tools, find the request and open the preview tab.
    – Jan Werkhoven
    Nov 12 '18 at 6:56




    So the issue is most likely the serializers. These are responsible for interpreting the JSON the API sent and then populates the Ember Data store. If this is done well, then you will see this in Ember Inspector. Given that we do not see data there, have a look at the JSON your API sent back. Do this by opening the network tab of Chrome dev tools, find the request and open the preview tab.
    – Jan Werkhoven
    Nov 12 '18 at 6:56




    1




    1




    i was missing the author entity from backend api and after fixing that it worked perfectly. thanks for your help and time to resolve this issue. much appreciated !
    – Thilina Dinith Fonseka
    Nov 27 '18 at 3:18




    i was missing the author entity from backend api and after fixing that it worked perfectly. thanks for your help and time to resolve this issue. much appreciated !
    – Thilina Dinith Fonseka
    Nov 27 '18 at 3:18




    1




    1




    You are most welcome :)
    – Jan Werkhoven
    Nov 27 '18 at 5:01




    You are most welcome :)
    – Jan Werkhoven
    Nov 27 '18 at 5:01













    1














    Ember is designed to be back-end agnostic. With the serialisers you can convert all JSON from incoming server responses to suit the Ember Data store. Similarily you use adapters to convert outgoing server requests to suit your back-end.



    I recommend reading this doc:



    https://guides.emberjs.com/release/models/customizing-serializers/



    Then choose from:





    • JSON API
      serializers (recommended)

    • REST
      serializers

    • Active Model serializers

    • Create your own custom
      serializer

    • Embedded records mixin






    share|improve this answer




























      1














      Ember is designed to be back-end agnostic. With the serialisers you can convert all JSON from incoming server responses to suit the Ember Data store. Similarily you use adapters to convert outgoing server requests to suit your back-end.



      I recommend reading this doc:



      https://guides.emberjs.com/release/models/customizing-serializers/



      Then choose from:





      • JSON API
        serializers (recommended)

      • REST
        serializers

      • Active Model serializers

      • Create your own custom
        serializer

      • Embedded records mixin






      share|improve this answer


























        1












        1








        1






        Ember is designed to be back-end agnostic. With the serialisers you can convert all JSON from incoming server responses to suit the Ember Data store. Similarily you use adapters to convert outgoing server requests to suit your back-end.



        I recommend reading this doc:



        https://guides.emberjs.com/release/models/customizing-serializers/



        Then choose from:





        • JSON API
          serializers (recommended)

        • REST
          serializers

        • Active Model serializers

        • Create your own custom
          serializer

        • Embedded records mixin






        share|improve this answer














        Ember is designed to be back-end agnostic. With the serialisers you can convert all JSON from incoming server responses to suit the Ember Data store. Similarily you use adapters to convert outgoing server requests to suit your back-end.



        I recommend reading this doc:



        https://guides.emberjs.com/release/models/customizing-serializers/



        Then choose from:





        • JSON API
          serializers (recommended)

        • REST
          serializers

        • Active Model serializers

        • Create your own custom
          serializer

        • Embedded records mixin







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 14 '18 at 8:56

























        answered Nov 12 '18 at 10:33









        Jan Werkhoven

        1,5721425




        1,5721425






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255803%2freplace-ember-arraycontroller-create-will-not-resolve-belongto-relationships%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ