@@ -6,22 +6,26 @@ import SaveRelationshipsMixin from 'ember-data-save-relationships';
66
77export default LandscapeSerializer . extend ( SaveRelationshipsMixin , {
88 attrs : {
9+ events :{ serialize :true } ,
910 systems :{ serialize :true } ,
1011 totalApplicationCommunications :{ serialize :true }
1112 } ,
1213 payloadKeyFromModelName ( model ) {
1314 return model ;
1415 } ,
1516 serializeRecordForIncluded ( key , relationship ) {
17+ if ( this . serializedTypes . indexOf ( key ) !== - 1 ) {
18+ return ;
19+ }
1620 if ( relationship . kind === 'belongsTo' ) {
1721 var nextSnapshot = this . belongsTo ( key ) ;
1822 nextSnapshot . serializedTypes = this . serializedTypes ;
1923 nextSnapshot . included = this . included ;
2024 if ( nextSnapshot . record . threeJSModel != undefined ) {
2125 nextSnapshot . record . set ( 'threeJSModel' , null ) ;
2226 }
23- if ( this . serializedTypes . indexOf ( nextSnapshot . get ( 'id' ) ) == - 1 ) {
24- this . serializedTypes . push ( nextSnapshot . get ( 'id' ) ) ;
27+ if ( this . serializedTypes . indexOf ( key ) == - 1 ) {
28+ this . serializedTypes . push ( key ) ;
2529 nextSnapshot . serializeRecordForIncluded = this . serializeRecordForIncluded ;
2630 if ( nextSnapshot . record . get ( 'id' ) != undefined ) {
2731 this . included . push ( nextSnapshot . record . serialize ( { includeId :true } ) . data ) ;
@@ -33,9 +37,10 @@ export default LandscapeSerializer.extend(SaveRelationshipsMixin,{
3337 var self = this ;
3438 var nkey = key ;
3539 var hasmany = this . hasMany ( nkey ) ;
40+ if ( hasmany != undefined ) {
3641 hasmany . forEach ( function ( v ) {
3742 if ( v . record . threeJSModel != undefined ) {
38- v . record . set ( 'threeJSModel' , null ) ;
43+ v . record . set ( 'threeJSModel' , null ) ;
3944 }
4045 if ( self . included == undefined ) {
4146 self . included = [ ] ;
@@ -45,31 +50,34 @@ export default LandscapeSerializer.extend(SaveRelationshipsMixin,{
4550 hasmany . forEach ( function ( value ) {
4651 value . serializedTypes = self . serializedTypes ;
4752 value . included = self . included ;
53+ if ( self . serializedTypes . indexOf ( nkey ) == - 1 ) {
54+ self . serializedTypes . push ( nkey ) ;
55+ }
4856 value . serializeRecordForIncluded = self . serializeRecordForIncluded ;
4957 value . eachRelationship ( self . serializeRecordForIncluded , value ) ;
5058 self . included . concat ( value . included ) ;
5159 } ) ;
5260 }
5361 } ) ;
5462 }
63+ }
5564 } ,
5665 serialize ( snapshot ) {
5766 let json = this . _super ( ...arguments ) ;
67+ // snapshot.hasMany('systems').forEach(function(v,k){
68+ // delete json.data.relationships.systems.data[k].attributes.threeJSModel;
69+ // });
70+ //
71+ // snapshot.hasMany('totalApplicationCommunications').forEach(function(v,k){
72+ // delete json.data.relationships.totalApplicationCommunications.data[k].attributes.threeJSModel;
73+ // });
5874
5975 snapshot . serializeRecordForIncluded = this . serializeRecordForIncluded ;
6076 snapshot . serializedTypes = [ ] ;
6177 snapshot . included = [ ] ;
6278 snapshot . eachRelationship ( this . serializeRecordForIncluded , snapshot ) ;
6379
64- snapshot . hasMany ( 'systems' ) . forEach ( function ( v , k ) {
65- delete json . data . relationships . systems . data [ k ] . attributes . threeJSModel ;
66- } ) ;
67-
68- snapshot . hasMany ( 'totalApplicationCommunications' ) . forEach ( function ( v , k ) {
69- delete json . data . relationships . totalApplicationCommunications . data [ k ] . attributes . threeJSModel ;
70- } ) ;
71-
72- json . included = snapshot . included ;
80+ json . included = snapshot . included ;
7381 var newjson = {
7482 data :{
7583 id : snapshot . record . get ( 'id' ) ,
@@ -100,7 +108,7 @@ json.included=snapshot.included;
100108 } ,
101109 normalizeResponse ( store , primaryModelClass , payload , id , requestType ) {
102110 var json = { } ;
103- if ( Array . isArray ( payload . data ) ) {
111+ if ( Array . isArray ( payload . data ) ) {
104112 json = { data :[ ] } ;
105113 payload . data . forEach ( function ( v , k ) {
106114 json . data [ k ] = JSON . parse ( v . attributes . landscape ) . data ;
@@ -119,10 +127,6 @@ json.included=snapshot.included;
119127 json . included = payload . included ;
120128 }
121129 }
122- // if(requestType=="queryRecord"){
123- // json.data=json.data[0];
124- // return this._super(store, primaryModelClass, json, id, requestType);
125- // }
126130 return this . _super ( store , primaryModelClass , json , id , requestType ) ;
127131 }
128132} ) ;
0 commit comments