dimanche 7 août 2016

Ember cannot read relationships

I have two models

import DS from 'ember-data';
export default DS.Model.extend({
  uid: DS.attr('number'),
  name: DS.attr('string'),
  fullName: DS.attr('string'),
  description: DS.attr('string'),
  homepage: DS.attr('string'),
  owner: DS.attr('string'),
  private: DS.attr('boolean'),

  organization: DS.belongsTo('organization')
});

and

import DS from 'ember-data';

export default DS.Model.extend({
  uid: DS.attr('string'),
  avatar: DS.attr('string'),
  blog: DS.attr('string'),
  company: DS.attr('string'),
  login: DS.attr('string'),
  location: DS.attr('string'),
  rooms: DS.hasMany('room')
});

when I load the data from server, I get

Error while processing route: rooms Assertion Failed: You need to pass a model name to the store's modelFor method Error: Assertion Failed: You need to pass a model name to the store's modelFor method

If I remove the relationship from room.js model, it works, but I cannot access the organizations in my template.

Just FYI: I have a serializer, because my server returns json without root:

import DS from 'ember-data';

export default DS.RESTSerializer.extend({
  primaryKey: 'uid',
  normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
    let typeKey = primaryModelClass.modelName;
    let ret = {};
    ret[typeKey] = payload;
    return this._normalizeResponse(store, primaryModelClass, ret, id, requestType, true);
  },

  normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
    let pluralTypeKey = Ember.Inflector.inflector.pluralize(primaryModelClass.modelName);
    let ret = {};
    ret[pluralTypeKey] = payload;
    return this._normalizeResponse(store, primaryModelClass, ret, id, requestType, false);
  }
});

and my route

export default Ember.Route.extend(AuthenticatedRouteMixin,{
  session: Ember.inject.service('session'),
  model(){
    return this.store.findAll('room');
  },




Aucun commentaire:

Enregistrer un commentaire