<NME> deserializer.js
<BEF> 'use strict'

var _ = require('lodash')

function defaultBeforeDeserialize (options, cb) {
  cb(null, options)
}

function defaultDeserialize (options, cb) {
  options.result = options.data.data.attributes || {}
  cb(null, options)
}

function defaultAfterDeserialize (options, cb) {
  cb(null, options)
        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);

        if (relationType === serverRelation.model) {
          if (serverRelation.foreignKey) {
            fk = serverRelation.foreignKey;
          } else {

            relationType = inflection.camelize(relationType, true);
            fk = relationType + fkSuffix;
          }
          result[fk] = relationValue;
        }
      }
    });
  }
  })
}

function belongsToRelationships (options) {
  var data = options.data
  var model = options.model

  if (!data || !data.data || !model || !data.data.relationships) {
    return
  }

  _.each(data.data.relationships, function (relationship, name) {
    var serverRelation = model.relations[name]
    if (!serverRelation) return
    var type = serverRelation.type

    // only handle belongsTo
    if (type !== 'belongsTo') return

    var fkName = serverRelation.keyFrom
    var modelTo = serverRelation.modelFrom

    if (!modelTo) return false

    if (!relationship.data) {
      options.result[fkName] = null
    } else {
      options.result[fkName] = relationship.data.id
    }
  })
}

<MSG> Fix relations

<DFF> @@ -16,34 +16,38 @@ module.exports = function Deserializer (data, serverRelations) {
         var fk = null;
         if (_.isArray(clientRelation.data)) {
           if (_.isEmpty(clientRelation.data)) {
-            return;
+            relationValue = [];
+          } else {
+            relationType = _.result(_.find(clientRelation.data, 'type'), 'type');
+            relationValue = _.map(clientRelation.data, function (val) {
+              return val.id;
+            });
           }
-          relationType = _.result(_.find(clientRelation.data, 'type'), 'type');
-          relationValue = _.map(clientRelation.data, function (val) {
-            return val.id;
-          });
           fkSuffix = 'Ids';
         } else {
           if (clientRelation.data === null) {
-            return;
+            relationValue = null;
+          } else {
+            relationType = clientRelation.data.type;
+            relationValue = clientRelation.data.id;
           }
-          relationType = clientRelation.data.type;
-          relationValue = clientRelation.data.id;
           fkSuffix = 'Id';
         }
-
-        relationType = inflection.singularize(relationType);
-
-        if (relationType === serverRelation.model) {
-          if (serverRelation.foreignKey) {
-            fk = serverRelation.foreignKey;
-          } else {
-
-            relationType = inflection.camelize(relationType, true);
-            fk = relationType + fkSuffix;
+        if (relationType === null) {
+          relationType = serverRelation.model;
+        } else {
+          relationType = inflection.singularize(relationType);
+          if (relationType !== serverRelation.model) {
+            return;
           }
-          result[fk] = relationValue;
         }
+        if (serverRelation.foreignKey) {
+          fk = serverRelation.foreignKey;
+        } else {
+          relationType = inflection.camelize(relationType, true);
+          fk = relationType + fkSuffix;
+        }
+        result[fk] = relationValue;
       }
     });
   }

Fix relations