@@ -1427,18 +1427,7 @@ class ParseObject {
14271427 queryOptions . sessionToken = options . sessionToken ;
14281428 }
14291429 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 ) ;
14421431 }
14431432 return CoreManager . getObjectController ( ) . fetch (
14441433 list ,
@@ -1481,6 +1470,41 @@ class ParseObject {
14811470 return ParseObject . fetchAll ( list , options ) ;
14821471 }
14831472
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+
14841508 /**
14851509 * Fetches the given list of Parse.Object if needed.
14861510 * If any error is encountered, stops and calls the error handler.
@@ -1508,13 +1532,32 @@ class ParseObject {
15081532 if ( options . hasOwnProperty ( 'sessionToken' ) ) {
15091533 queryOptions . sessionToken = options . sessionToken ;
15101534 }
1535+ if ( options . hasOwnProperty ( 'include' ) ) {
1536+ queryOptions . include = ParseObject . handleIncludeOptions ( options ) ;
1537+ }
15111538 return CoreManager . getObjectController ( ) . fetch (
15121539 list ,
15131540 false ,
15141541 queryOptions
15151542 ) ;
15161543 }
15171544
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+
15181561 /**
15191562 * Destroy the given list of models on the server if it was already persisted.
15201563 *
0 commit comments