@@ -16,34 +16,38 @@ module.exports = function Deserializer (data, serverRelations) {
1616 var fk = null ;
1717 if ( _ . isArray ( clientRelation . data ) ) {
1818 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+ } ) ;
2025 }
21- relationType = _ . result ( _ . find ( clientRelation . data , 'type' ) , 'type' ) ;
22- relationValue = _ . map ( clientRelation . data , function ( val ) {
23- return val . id ;
24- } ) ;
2526 fkSuffix = 'Ids' ;
2627 } else {
2728 if ( clientRelation . data === null ) {
28- return ;
29+ relationValue = null ;
30+ } else {
31+ relationType = clientRelation . data . type ;
32+ relationValue = clientRelation . data . id ;
2933 }
30- relationType = clientRelation . data . type ;
31- relationValue = clientRelation . data . id ;
3234 fkSuffix = 'Id' ;
3335 }
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 ;
4442 }
45- result [ fk ] = relationValue ;
4643 }
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 ;
4751 }
4852 } ) ;
4953 }
0 commit comments