Quantcast
Viewing all articles
Browse latest Browse all 4826

Ember Data Serializer TypeError while saving record

@skoslitz wrote:

I am using JSONAPISerializer/JSONAPIAdapter for my backend(JSONAPI spec conform). All GET requests are working fine.
I have issues with saving records. While saving a record the serializer creates this error:
TypeError: Invalid Fullname, expected:type:namegot: model:(…)

Strangely, the POST request is send properly and saved at the backend but Ember stucks. Here are some details for serializer and adapter:

export default DS.JSONAPIAdapter.extend({
	host: 'http://localhost:1313',
	namespace: 'api/page',
	pathForType: function(modelName) {
    	return "regionen";
  },
  createRecord: function(store, type, snapshot) {
      console.log("-->", type.modelName);
      let url = `${this.host}/${this.namespace}/${snapshot.attr('path')}`;
      let data = {};
      let serializer = store.serializerFor(type.modelName);
      serializer.serializeIntoHash(data, type, snapshot);
      return $.ajax({
        type: 'POST',
        url: url,
        data: JSON.stringify(data)
      });
  }, ...

export default DS.JSONAPISerializer.extend({
  	normalize(modelClass, resourceHash, prop) {
  		resourceHash.attributes.bandnummer = `${resourceHash.attributes.metadata.bandnummer}`
  		resourceHash.attributes.title = `${resourceHash.attributes.metadata.title}`
  		return this._super(...arguments)
  	},
  	serializeIntoHash(hash, typeClass, snapshot) {
		hash["page"] = this.serialize(snapshot);
	},
	serialize(snapshot) {
		let serializedData = {
			"attributes": {
				"path": snapshot.attr("path"),
				"metadata": {
					"title": snapshot.attr("title"),
					"bandnummer": snapshot.attr("bandnummer")   					
				},
				"content": snapshot.attr("content")
			}			
		};

		if (snapshot.id) {
			serializedData.id = snapshot.id;
		};    		   			
		return serializedData;
	}
});

Any helpful suggestions to solve this?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles