<commit_before>import Ember from "ember";
import DS from "ember-data";

export default DS.RESTSerializer.extend({

	normalize: function(type, hash, prop) {
		this._parseLinkables(hash);
		return this._super(type, hash, prop);
	},

	serialize: function(snapshot, options) {
		var json = this._super(snapshot, options);
		var id = snapshot.id;
		// get the id of the record and create a self-link with that id
		if (!Ember.isNone(id)) {
			json.links = [{
				'id': id,
				'rel': 'self'
			}];
		}
		// check each relationship
		// replace belongTo relationships with an object with self-links containing the id
		// replace hasMany relationships with an array of self-links containing the id
		snapshot.eachRelationship(function(name, relationship) {
			var recordValue;
			if (relationship.kind === 'hasMany') {
				json[name] = [];

				recordValue = snapshot.hasMany(name);

				if (!Ember.isNone(recordValue)) {
					recordValue.mapBy('id').forEach(function(relId) {
						json[name].push({
							links: [{
								'id': relId,
								'rel': 'self'
							}]
						});
					});
				}
			} else {
				json[name] = null;
				recordValue = snapshot.belongsTo(name);

				if (!Ember.isNone(recordValue)) {
					json[name] = {
						links: [{
							'id': recordValue.id,
							'rel': 'self'
						}]
					};
				}
			}
		});
		return json;
	},

	_parseLinkables: function(hash) {
		var self = this;
		// check properties of hash for more linkables
		if (Ember.isNone(hash) || (!Ember.isArray(hash) && (typeof hash !== 'object'))) return;

		if (!Ember.isNone(hash.additionalObjects)) {
			// Verplaats additionalObjects naar het bovenliggende object
			Ember.keys(hash.additionalObjects).forEach(function (key){
				hash[key] = hash.additionalObjects[key];
			});
			delete hash.additionalObjects;<commit_msg>Als recordValue er wel is, maar het id is null dan willen we deze niet in een linkable hebben. Dat gaat fout als we relaties willen 'nullen'.<commit_after>import Ember from 'ember';
import DS from 'ember-data';

export default DS.RESTSerializer.extend({

	normalize: function(type, hash, prop) {
		this._parseLinkables(hash);
		return this._super(type, hash, prop);
	},

	serialize: function(snapshot, options) {
		var json = this._super(snapshot, options);
		var id = snapshot.id;
		// get the id of the record and create a self-link with that id
		if (!Ember.isNone(id)) {
			json.links = [{
				'id': id,
				'rel': 'self'
			}];
		}
		// check each relationship
		// replace belongTo relationships with an object with self-links containing the id
		// replace hasMany relationships with an array of self-links containing the id
		snapshot.eachRelationship(function(name, relationship) {
			var recordValue;
			if (relationship.kind === 'hasMany') {
				json[name] = [];

				recordValue = snapshot.hasMany(name);

				if (!Ember.isNone(recordValue)) {
					recordValue.mapBy('id').forEach(function(relId) {
						json[name].push({
							links: [{
								'id': relId,
								'rel': 'self'
							}]
						});
					});
				}
			} else {
				json[name] = null;
				recordValue = snapshot.belongsTo(name);

				if (!Ember.isNone(recordValue.id)) {
					json[name] = {
						links: [{
							'id': recordValue.id,
							'rel': 'self'
						}]
					};
				}
			}
		});
		return json;
	},

	_parseLinkables: function(hash) {
		var self = this;
		// check properties of hash for more linkables
		if (Ember.isNone(hash) || (!Ember.isArray(hash) && (typeof hash !== 'object'))) return;

		if (!Ember.isNone(hash.additionalObjects)) {
			// Verplaats additionalObjects naar het bovenliggende object
			Ember.keys(hash.additionalObjects).forEach(function (key){
				hash[key] = hash.additionalObjects[key];
			});
			delete hash.additionalObjects;
{'fraction_non_alphanumeric': 0.14007989347536617, 'fraction_numerical': 0.0, 'mean_word_length': 3.0915032679738563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2206581', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1185, 'n_words': 309}