File tree 2 files changed +43
-3
lines changed
2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -261,24 +261,27 @@ export default class ParseQuery {
261
261
find ( options ? : FullOptions ) : ParsePromise {
262
262
options = options || { } ;
263
263
264
- var findOptions = { } ;
264
+ let findOptions = { } ;
265
265
if ( options . hasOwnProperty ( 'useMasterKey' ) ) {
266
266
findOptions . useMasterKey = options . useMasterKey ;
267
267
}
268
268
if ( options . hasOwnProperty ( 'sessionToken' ) ) {
269
269
findOptions . sessionToken = options . sessionToken ;
270
270
}
271
271
272
- var controller = CoreManager . getQueryController ( ) ;
272
+ let controller = CoreManager . getQueryController ( ) ;
273
273
274
274
return controller . find (
275
275
this . className ,
276
276
this . toJSON ( ) ,
277
277
findOptions
278
278
) . then ( ( response ) => {
279
279
return response . results . map ( ( data ) => {
280
+ // In cases of relations, the server may send back a className
281
+ // on the top level of the payload
282
+ let override = response . className || this . className ;
280
283
if ( ! data . className ) {
281
- data . className = this . className ;
284
+ data . className = override ;
282
285
}
283
286
return ParseObject . fromJSON ( data ) ;
284
287
} ) ;
Original file line number Diff line number Diff line change @@ -1298,4 +1298,41 @@ describe('ParseQuery', () => {
1298
1298
q = new ParseQuery ( 'User' ) ;
1299
1299
expect ( q . className ) . toBe ( 'User' ) ;
1300
1300
} ) ;
1301
+
1302
+ it ( 'does not override the className if it comes from the server' , asyncHelper ( ( done ) => {
1303
+ CoreManager . setQueryController ( {
1304
+ find ( className , params , options ) {
1305
+ return ParsePromise . as ( {
1306
+ results : [
1307
+ { className : 'Product' , objectId : 'P40' , name : 'Product 40' } ,
1308
+ ]
1309
+ } ) ;
1310
+ }
1311
+ } ) ;
1312
+
1313
+ var q = new ParseQuery ( 'Item' ) ;
1314
+ q . find ( ) . then ( ( results ) => {
1315
+ expect ( results [ 0 ] . className ) . toBe ( 'Product' ) ;
1316
+ done ( ) ;
1317
+ } ) ;
1318
+ } ) ) ;
1319
+
1320
+ it ( 'can override the className with a name from the server' , asyncHelper ( ( done ) => {
1321
+ CoreManager . setQueryController ( {
1322
+ find ( className , params , options ) {
1323
+ return ParsePromise . as ( {
1324
+ results : [
1325
+ { objectId : 'P41' , name : 'Product 41' } ,
1326
+ ] ,
1327
+ className : 'Product'
1328
+ } ) ;
1329
+ }
1330
+ } ) ;
1331
+
1332
+ var q = new ParseQuery ( 'Item' ) ;
1333
+ q . find ( ) . then ( ( results ) => {
1334
+ expect ( results [ 0 ] . className ) . toBe ( 'Product' ) ;
1335
+ done ( ) ;
1336
+ } ) ;
1337
+ } ) ) ;
1301
1338
} ) ;
You can’t perform that action at this time.
0 commit comments