@@ -1427,18 +1427,7 @@ class ParseObject {
1427
1427
queryOptions . sessionToken = options . sessionToken ;
1428
1428
}
1429
1429
if ( options . hasOwnProperty ( 'include' ) ) {
1430
- queryOptions . include = [ ] ;
1431
- if ( Array . isArray ( options . include ) ) {
1432
- options . include . forEach ( ( key ) => {
1433
- if ( Array . isArray ( key ) ) {
1434
- queryOptions . include = queryOptions . include . concat ( key ) ;
1435
- } else {
1436
- queryOptions . include . push ( key ) ;
1437
- }
1438
- } ) ;
1439
- } else {
1440
- queryOptions . include . push ( options . include ) ;
1441
- }
1430
+ queryOptions . include = ParseObject . handleIncludeOptions ( options ) ;
1442
1431
}
1443
1432
return CoreManager . getObjectController ( ) . fetch (
1444
1433
list ,
@@ -1481,6 +1470,41 @@ class ParseObject {
1481
1470
return ParseObject . fetchAll ( list , options ) ;
1482
1471
}
1483
1472
1473
+ /**
1474
+ * Fetches the given list of Parse.Object if needed.
1475
+ * If any error is encountered, stops and calls the error handler.
1476
+ *
1477
+ * Includes nested Parse.Objects for the provided key. You can use dot
1478
+ * notation to specify which fields in the included object are also fetched.
1479
+ *
1480
+ * If any error is encountered, stops and calls the error handler.
1481
+ *
1482
+ * <pre>
1483
+ * Parse.Object.fetchAllIfNeededWithInclude([object1, object2, ...], [pointer1, pointer2, ...])
1484
+ * .then((list) => {
1485
+ * // All the objects were fetched.
1486
+ * }, (error) => {
1487
+ * // An error occurred while fetching one of the objects.
1488
+ * });
1489
+ * </pre>
1490
+ *
1491
+ * @param {Array } list A list of <code>Parse.Object</code>.
1492
+ * @param {String|Array<string|Array<string>> } keys The name(s) of the key(s) to include.
1493
+ * @param {Object } options
1494
+ * Valid options are:<ul>
1495
+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1496
+ * be used for this request.
1497
+ * <li>sessionToken: A valid session token, used for making a request on
1498
+ * behalf of a specific user.
1499
+ * </ul>
1500
+ * @static
1501
+ */
1502
+ static fetchAllIfNeededWithInclude ( list : Array < ParseObject > , keys : String | Array < string | Array < string >> , options : RequestOptions ) {
1503
+ options = options || { } ;
1504
+ options . include = keys ;
1505
+ return ParseObject . fetchAllIfNeeded ( list , options ) ;
1506
+ }
1507
+
1484
1508
/**
1485
1509
* Fetches the given list of Parse.Object if needed.
1486
1510
* If any error is encountered, stops and calls the error handler.
@@ -1508,13 +1532,32 @@ class ParseObject {
1508
1532
if ( options . hasOwnProperty ( 'sessionToken' ) ) {
1509
1533
queryOptions . sessionToken = options . sessionToken ;
1510
1534
}
1535
+ if ( options . hasOwnProperty ( 'include' ) ) {
1536
+ queryOptions . include = ParseObject . handleIncludeOptions ( options ) ;
1537
+ }
1511
1538
return CoreManager . getObjectController ( ) . fetch (
1512
1539
list ,
1513
1540
false ,
1514
1541
queryOptions
1515
1542
) ;
1516
1543
}
1517
1544
1545
+ static handleIncludeOptions ( options ) {
1546
+ let include = [ ] ;
1547
+ if ( Array . isArray ( options . include ) ) {
1548
+ options . include . forEach ( ( key ) => {
1549
+ if ( Array . isArray ( key ) ) {
1550
+ include = include . concat ( key ) ;
1551
+ } else {
1552
+ include . push ( key ) ;
1553
+ }
1554
+ } ) ;
1555
+ } else {
1556
+ include. push ( options . include ) ;
1557
+ }
1558
+ return include ;
1559
+ }
1560
+
1518
1561
/**
1519
1562
* Destroy the given list of models on the server if it was already persisted.
1520
1563
*
0 commit comments