jeudi 15 octobre 2015

Serialize data model with relation

Ok so here the case, i try to implement this "ember-parse-adapter-simple-auth" currentUser initializer

btw this is their original code, taken from http://ift.tt/1QvMFrT

import Ember from 'ember';
import Session from 'simple-auth/session';

export default {
  name: 'parse-current-user',
  before: 'simple-auth',
  initialize: function(container) {
    Session.reopen({
      currentUser: function() {
        var userData = this.get('secure.userData');

        if(Ember.isEmpty(userData)) {
          return null;
        } else {
          var store = container.lookup('store:main');
          var model = store.modelFor('parse-user');
          var serializer = store.serializerFor(model);
          serializer.normalize(model, userData);
          var record = store.push(model, userData);
          return record;
        }
      }.property('secure.userData')
    });
  }
};

but it throw error

Assertion Failed: You must use Ember.set() to set the `user_type` property (of [object Object]) to `patron`."

as i trace it, the userData, feeded is

{"active":true,"createdAt":"2015-10-07T04:25:44.180Z","email":"markelia@pubsport.com","objectId":"ZpsnNMfQvf","patron":{"__type":"Pointer","className":"Patron","objectId":"xEnarmitZE"},"updatedAt":"2015-10-07T04:25:44.180Z","user_type":"patron","username":"markelia"}

it error right at this line

serializer.normalize(model, userData);

Any ideas how to solve this?




Aucun commentaire:

Enregistrer un commentaire