@@ -6,26 +6,22 @@ import SaveRelationshipsMixin from 'ember-data-save-relationships';
66
77export default LandscapeSerializer . extend ( SaveRelationshipsMixin , {
88 attrs : {
9- events :{ serialize :true } ,
109 systems :{ serialize :true } ,
1110 totalApplicationCommunications :{ serialize :true }
1211 } ,
1312 payloadKeyFromModelName ( model ) {
1413 return model ;
1514 } ,
1615 serializeRecordForIncluded ( key , relationship ) {
17- if ( this . serializedTypes . indexOf ( key ) !== - 1 ) {
18- return ;
19- }
2016 if ( relationship . kind === 'belongsTo' ) {
2117 var nextSnapshot = this . belongsTo ( key ) ;
2218 nextSnapshot . serializedTypes = this . serializedTypes ;
2319 nextSnapshot . included = this . included ;
2420 if ( nextSnapshot . record . threeJSModel != undefined ) {
2521 nextSnapshot . record . set ( 'threeJSModel' , null ) ;
2622 }
27- if ( this . serializedTypes . indexOf ( key ) == - 1 ) {
28- this . serializedTypes . push ( key ) ;
23+ if ( this . serializedTypes . indexOf ( nextSnapshot . get ( 'id' ) ) == - 1 ) {
24+ this . serializedTypes . push ( nextSnapshot . get ( 'id' ) ) ;
2925 nextSnapshot . serializeRecordForIncluded = this . serializeRecordForIncluded ;
3026 if ( nextSnapshot . record . get ( 'id' ) != undefined ) {
3127 this . included . push ( nextSnapshot . record . serialize ( { includeId :true } ) . data ) ;
@@ -37,10 +33,9 @@ export default LandscapeSerializer.extend(SaveRelationshipsMixin,{
3733 var self = this ;
3834 var nkey = key ;
3935 var hasmany = this . hasMany ( nkey ) ;
40- if ( hasmany != undefined ) {
4136 hasmany . forEach ( function ( v ) {
4237 if ( v . record . threeJSModel != undefined ) {
43- v . record . set ( 'threeJSModel' , null ) ;
38+ v . record . set ( 'threeJSModel' , null ) ;
4439 }
4540 if ( self . included == undefined ) {
4641 self . included = [ ] ;
@@ -51,7 +46,7 @@ export default LandscapeSerializer.extend(SaveRelationshipsMixin,{
5146 value . serializedTypes = self . serializedTypes ;
5247 value . included = self . included ;
5348 if ( self . serializedTypes . indexOf ( nkey ) == - 1 ) {
54- self . serializedTypes . push ( nkey ) ;
49+ self . serializedTypes . push ( nextSnapshot . get ( 'id' ) ) ;
5550 }
5651 value . serializeRecordForIncluded = self . serializeRecordForIncluded ;
5752 value . eachRelationship ( self . serializeRecordForIncluded , value ) ;
@@ -60,24 +55,24 @@ export default LandscapeSerializer.extend(SaveRelationshipsMixin,{
6055 }
6156 } ) ;
6257 }
63- }
6458 } ,
6559 serialize ( snapshot ) {
6660 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- // });
7461
7562 snapshot . serializeRecordForIncluded = this . serializeRecordForIncluded ;
7663 snapshot . serializedTypes = [ ] ;
7764 snapshot . included = [ ] ;
7865 snapshot . eachRelationship ( this . serializeRecordForIncluded , snapshot ) ;
7966
80- json . included = snapshot . included ;
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+ } ) ;
74+
75+ json . included = snapshot . included ;
8176 var newjson = {
8277 data :{
8378 id : snapshot . record . get ( 'id' ) ,
@@ -108,7 +103,7 @@ export default LandscapeSerializer.extend(SaveRelationshipsMixin,{
108103 } ,
109104 normalizeResponse ( store , primaryModelClass , payload , id , requestType ) {
110105 var json = { } ;
111- if ( Array . isArray ( payload . data ) ) {
106+ if ( Array . isArray ( payload . data ) ) {
112107 json = { data :[ ] } ;
113108 payload . data . forEach ( function ( v , k ) {
114109 json . data [ k ] = JSON . parse ( v . attributes . landscape ) . data ;
@@ -127,6 +122,10 @@ export default LandscapeSerializer.extend(SaveRelationshipsMixin,{
127122 json . included = payload . included ;
128123 }
129124 }
125+ // if(requestType=="queryRecord"){
126+ // json.data=json.data[0];
127+ // return this._super(store, primaryModelClass, json, id, requestType);
128+ // }
130129 return this . _super ( store , primaryModelClass , json , id , requestType ) ;
131130 }
132131} ) ;
0 commit comments