<commit_before>var _ = require('lodash');
var inflection = require('inflection');

module.exports = function Deserializer (data, serverRelations) {

  var clientRelations = data.data.relationships;
  var result = data.data.attributes || {};
  if (_.isPlainObject(clientRelations)) {
    _.each(clientRelations, function (clientRelation, clientRelationName) {
      var serverRelation = serverRelations[clientRelationName];

      if (_.isPlainObject(serverRelation)) {
        var relationType = null;
        var relationValue = null;
        var fkSuffix = null;
        var fk = null;
        if (_.isArray(clientRelation.data)) {
          relationType = _.result(_.find(clientRelation.data, 'type'), 'type');
          relationValue = _.map(clientRelation.data, function (val) {
            return val.id;
          });
          fkSuffix = 'Ids';
        } else {
          relationType = clientRelation.data.type;
          relationValue = clientRelation.data.id;
          fkSuffix = 'Id';
        }

        relationType = inflection.singularize(relationType);<commit_msg>Fix error if relation empty<commit_after>var _ = require('lodash');
var inflection = require('inflection');

module.exports = function Deserializer (data, serverRelations) {

  var clientRelations = data.data.relationships;
  var result = data.data.attributes || {};
  if (_.isPlainObject(clientRelations)) {
    _.each(clientRelations, function (clientRelation, clientRelationName) {
      var serverRelation = serverRelations[clientRelationName];

      if (_.isPlainObject(serverRelation)) {
        var relationType = null;
        var relationValue = null;
        var fkSuffix = null;
        var fk = null;
        if (_.isArray(clientRelation.data)) {
          if (_.isEmpty(clientRelation.data)) {
            return;
          }
          relationType = _.result(_.find(clientRelation.data, 'type'), 'type');
          relationValue = _.map(clientRelation.data, function (val) {
            return val.id;
          });
          fkSuffix = 'Ids';
        } else {
          if (clientRelation.data === null) {
            return;
          }
          relationType = clientRelation.data.type;
          relationValue = clientRelation.data.id;
          fkSuffix = 'Id';
        }

        relationType = inflection.singularize(relationType);
{'fraction_non_alphanumeric': 0.11311053984575835, 'fraction_numerical': 0.0, 'mean_word_length': 2.581288343558282, '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': '5353004', 'n_tokens_mistral': 668, 'n_tokens_neox': 647, 'n_words': 134}