@@ -970,6 +970,8 @@ class ParseObject {
970970 * be used for this request.
971971 * <li>sessionToken: A valid session token, used for making a request on
972972 * behalf of a specific user.
973+ * <li>include: The name(s) of the key(s) to include. Can be a string, an array of strings,
974+ * or an array of array of strings.
973975 * </ul>
974976 * @return {Promise } A promise that is fulfilled when the fetch
975977 * completes.
@@ -983,10 +985,48 @@ class ParseObject {
983985 if ( options . hasOwnProperty ( 'sessionToken' ) ) {
984986 fetchOptions . sessionToken = options . sessionToken ;
985987 }
988+ if ( options . hasOwnProperty ( 'include' ) ) {
989+ fetchOptions . include = [ ] ;
990+ if ( Array . isArray ( options . include ) ) {
991+ options . include . forEach ( ( key ) => {
992+ if ( Array . isArray ( key ) ) {
993+ fetchOptions . include = fetchOptions . include . concat ( key ) ;
994+ } else {
995+ fetchOptions . include . push ( key ) ;
996+ }
997+ } ) ;
998+ } else {
999+ fetchOptions . include . push ( options . include ) ;
1000+ }
1001+ }
9861002 var controller = CoreManager . getObjectController ( ) ;
9871003 return controller . fetch ( this , true , fetchOptions ) ;
9881004 }
9891005
1006+ /**
1007+ * Fetch the model from the server. If the server's representation of the
1008+ * model differs from its current attributes, they will be overriden.
1009+ *
1010+ * Includes nested Parse.Objects for the provided key. You can use dot
1011+ * notation to specify which fields in the included object are also fetched.
1012+ *
1013+ * @param {String|Array<string|Array<string>> } keys The name(s) of the key(s) to include.
1014+ * @param {Object } options
1015+ * Valid options are:<ul>
1016+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1017+ * be used for this request.
1018+ * <li>sessionToken: A valid session token, used for making a request on
1019+ * behalf of a specific user.
1020+ * </ul>
1021+ * @return {Promise } A promise that is fulfilled when the fetch
1022+ * completes.
1023+ */
1024+ fetchWithInclude ( keys : String | Array < string | Array < string >> , options : RequestOptions ) : Promise {
1025+ options = options || { } ;
1026+ options . include = keys ;
1027+ return this . fetch ( options ) ;
1028+ }
1029+
9901030 /**
9911031 * Set a hash of model attributes, and save the model to the server.
9921032 * updatedAt will be updated when the request returns.
@@ -1133,9 +1173,17 @@ class ParseObject {
11331173 *
11341174 * @param {Array } list A list of <code>Parse.Object</code>.
11351175 * @param {Object } options
1176+ * Valid options are:<ul>
1177+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1178+ * be used for this request.
1179+ * <li>sessionToken: A valid session token, used for making a request on
1180+ * behalf of a specific user.
1181+ * <li>include: The name(s) of the key(s) to include. Can be a string, an array of strings,
1182+ * or an array of array of strings.
1183+ * </ul>
11361184 * @static
11371185 */
1138- static fetchAll ( list : Array < ParseObject > , options ) {
1186+ static fetchAll ( list : Array < ParseObject > , options : RequestOptions ) {
11391187 var options = options || { } ;
11401188
11411189 var queryOptions = { } ;
@@ -1145,13 +1193,61 @@ class ParseObject {
11451193 if ( options . hasOwnProperty ( 'sessionToken' ) ) {
11461194 queryOptions . sessionToken = options . sessionToken ;
11471195 }
1196+ if ( options . hasOwnProperty ( 'include' ) ) {
1197+ queryOptions . include = [ ] ;
1198+ if ( Array . isArray ( options . include ) ) {
1199+ options . include . forEach ( ( key ) => {
1200+ if ( Array . isArray ( key ) ) {
1201+ queryOptions . include = queryOptions . include . concat ( key ) ;
1202+ } else {
1203+ queryOptions . include . push ( key ) ;
1204+ }
1205+ } ) ;
1206+ } else {
1207+ queryOptions . include . push ( options . include ) ;
1208+ }
1209+ }
11481210 return CoreManager . getObjectController ( ) . fetch (
11491211 list ,
11501212 true ,
11511213 queryOptions
11521214 ) ;
11531215 }
11541216
1217+ /**
1218+ * Fetches the given list of Parse.Object.
1219+ *
1220+ * Includes nested Parse.Objects for the provided key. You can use dot
1221+ * notation to specify which fields in the included object are also fetched.
1222+ *
1223+ * If any error is encountered, stops and calls the error handler.
1224+ *
1225+ * <pre>
1226+ * Parse.Object.fetchAllWithInclude([object1, object2, ...], [pointer1, pointer2, ...])
1227+ * .then((list) => {
1228+ * // All the objects were fetched.
1229+ * }, (error) => {
1230+ * // An error occurred while fetching one of the objects.
1231+ * });
1232+ * </pre>
1233+ *
1234+ * @param {Array } list A list of <code>Parse.Object</code>.
1235+ * @param {String|Array<string|Array<string>> } keys The name(s) of the key(s) to include.
1236+ * @param {Object } options
1237+ * Valid options are:<ul>
1238+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
1239+ * be used for this request.
1240+ * <li>sessionToken: A valid session token, used for making a request on
1241+ * behalf of a specific user.
1242+ * </ul>
1243+ * @static
1244+ */
1245+ static fetchAllWithInclude ( list : Array < ParseObject > , keys : String | Array < string | Array < string >> , options : RequestOptions ) {
1246+ options = options || { } ;
1247+ options . include = keys ;
1248+ return ParseObject . fetchAll ( list , options ) ;
1249+ }
1250+
11551251 /**
11561252 * Fetches the given list of Parse.Object if needed.
11571253 * If any error is encountered, stops and calls the error handler.
@@ -1570,6 +1666,9 @@ var DefaultController = {
15701666 }
15711667 var query = new ParseQuery ( className ) ;
15721668 query . containedIn ( 'objectId' , ids ) ;
1669+ if ( options && options . include ) {
1670+ query . include ( options . include ) ;
1671+ }
15731672 query . _limit = ids . length ;
15741673 return query . find ( options ) . then ( ( objects ) => {
15751674 var idMap = { } ;
@@ -1604,10 +1703,14 @@ var DefaultController = {
16041703 } ) ;
16051704 } else {
16061705 var RESTController = CoreManager . getRESTController ( ) ;
1706+ const params = { } ;
1707+ if ( options && options . include ) {
1708+ params . include = options . include . join ( ) ;
1709+ }
16071710 return RESTController . request (
16081711 'GET' ,
16091712 'classes/' + target . className + '/' + target . _getId ( ) ,
1610- { } ,
1713+ params ,
16111714 options
16121715 ) . then ( ( response , status , xhr ) => {
16131716 if ( target instanceof ParseObject ) {
0 commit comments