File tree Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Expand file tree Collapse file tree 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 {
261261 find ( options ? : FullOptions ) : ParsePromise {
262262 options = options || { } ;
263263
264- var findOptions = { } ;
264+ let findOptions = { } ;
265265 if ( options . hasOwnProperty ( 'useMasterKey' ) ) {
266266 findOptions . useMasterKey = options . useMasterKey ;
267267 }
268268 if ( options . hasOwnProperty ( 'sessionToken' ) ) {
269269 findOptions . sessionToken = options . sessionToken ;
270270 }
271271
272- var controller = CoreManager . getQueryController ( ) ;
272+ let controller = CoreManager . getQueryController ( ) ;
273273
274274 return controller . find (
275275 this . className ,
276276 this . toJSON ( ) ,
277277 findOptions
278278 ) . then ( ( response ) => {
279279 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 ;
280283 if ( ! data . className ) {
281- data . className = this . className ;
284+ data . className = override ;
282285 }
283286 return ParseObject . fromJSON ( data ) ;
284287 } ) ;
Original file line number Diff line number Diff line change @@ -1298,4 +1298,41 @@ describe('ParseQuery', () => {
12981298 q = new ParseQuery ( 'User' ) ;
12991299 expect ( q . className ) . toBe ( 'User' ) ;
13001300 } ) ;
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+ } ) ) ;
13011338} ) ;
You can’t perform that action at this time.
0 commit comments