mercredi 25 janvier 2017

Ember store returns class containing model data but not model instance

I am trying to use ember's store to send requests to the api for data. I am so close to getting it working, but for some reason, the model data doesn't display in the template.

I get a response back from the server which looks like this:

artist_profile: {
   alias:"alias",
   bio:"biofda",
   created_at:Tue Nov 22 2016 10:50:27 GMT-0500 (EST),
   location:"location",
   portfolio_link:"link",
   updated_at:Thu Dec 22 2016 20:55:38 GMT-0500 (EST)
}

But when it goes through the serializer, it is set on the model like this:

Route model:

...
data: {
  alias:"alias",
  bio:"biofda",
  created_at:Tue Nov 22 2016 10:50:27 GMT-0500 (EST),
  location:"location",
  portfolio_link:"link",
  updated_at:Thu Dec 22 2016 20:55:38 GMT-0500 (EST),
},
id:"980190976",
...

I think this is why it is not rendering properly on the template. In fact if i debugger into the route and call this.model.alias, it is returned as undefined. but if i do route.get('model').get('alias'), it returns the alias value.

Anyone know what I'm doing wrong to prevent the store from properly returning a model that the template can render?

More code:

Adapter:

 export default DS.RESTAdapter.extend({
    host: CONFIG.API_HOST,
    pathForType() {
      return 'artist_profiles';
    }
  });

Serializer:

import DS from 'ember-data';

export default DS.RESTSerializer.extend({
  normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
    payload = { artist_profiles: payload.artist_profile };
    return this._super(store, primaryModelClass, payload, id, requestType);
  }
});

Model class:

import DS from 'ember-data';

const {
  Model,
  attr,
  belongsTo
} = DS;

export default Model.extend({
  alias: attr('string'),
  bio: attr('string'),
  portfolio_link: attr('string'),
  location: attr('string')
});

Route model hook:

model() {
  return this.get('store').find('artist-profile', 980190976);
}

Template:

ARTIST PROFIlE <br>










Aucun commentaire:

Enregistrer un commentaire