@@ -16,34 +16,38 @@ module.exports = function Deserializer (data, serverRelations) {
16
16
var fk = null ;
17
17
if ( _ . isArray ( clientRelation . data ) ) {
18
18
if ( _ . isEmpty ( clientRelation . data ) ) {
19
- return ;
19
+ relationValue = [ ] ;
20
+ } else {
21
+ relationType = _ . result ( _ . find ( clientRelation . data , 'type' ) , 'type' ) ;
22
+ relationValue = _ . map ( clientRelation . data , function ( val ) {
23
+ return val . id ;
24
+ } ) ;
20
25
}
21
- relationType = _ . result ( _ . find ( clientRelation . data , 'type' ) , 'type' ) ;
22
- relationValue = _ . map ( clientRelation . data , function ( val ) {
23
- return val . id ;
24
- } ) ;
25
26
fkSuffix = 'Ids' ;
26
27
} else {
27
28
if ( clientRelation . data === null ) {
28
- return ;
29
+ relationValue = null ;
30
+ } else {
31
+ relationType = clientRelation . data . type ;
32
+ relationValue = clientRelation . data . id ;
29
33
}
30
- relationType = clientRelation . data . type ;
31
- relationValue = clientRelation . data . id ;
32
34
fkSuffix = 'Id' ;
33
35
}
34
-
35
- relationType = inflection . singularize ( relationType ) ;
36
-
37
- if ( relationType === serverRelation . model ) {
38
- if ( serverRelation . foreignKey ) {
39
- fk = serverRelation . foreignKey ;
40
- } else {
41
-
42
- relationType = inflection . camelize ( relationType , true ) ;
43
- fk = relationType + fkSuffix ;
36
+ if ( relationType === null ) {
37
+ relationType = serverRelation . model ;
38
+ } else {
39
+ relationType = inflection . singularize ( relationType ) ;
40
+ if ( relationType !== serverRelation . model ) {
41
+ return ;
44
42
}
45
- result [ fk ] = relationValue ;
46
43
}
44
+ if ( serverRelation . foreignKey ) {
45
+ fk = serverRelation . foreignKey ;
46
+ } else {
47
+ relationType = inflection . camelize ( relationType , true ) ;
48
+ fk = relationType + fkSuffix ;
49
+ }
50
+ result [ fk ] = relationValue ;
47
51
}
48
52
} ) ;
49
53
}
0 commit comments