@@ -970,6 +970,8 @@ class ParseObject {
970
970
* be used for this request.
971
971
* <li>sessionToken: A valid session token, used for making a request on
972
972
* 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.
973
975
* </ul>
974
976
* @return {Promise } A promise that is fulfilled when the fetch
975
977
* completes.
@@ -983,10 +985,48 @@ class ParseObject {
983
985
if ( options . hasOwnProperty ( 'sessionToken' ) ) {
984
986
fetchOptions . sessionToken = options . sessionToken ;
985
987
}
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
+ }
986
1002
var controller = CoreManager . getObjectController ( ) ;
987
1003
return controller . fetch ( this , true , fetchOptions ) ;
988
1004
}
989
1005
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
+
990
1030
/**
991
1031
* Set a hash of model attributes, and save the model to the server.
992
1032
* updatedAt will be updated when the request returns.
@@ -1133,9 +1173,17 @@ class ParseObject {
1133
1173
*
1134
1174
* @param {Array } list A list of <code>Parse.Object</code>.
1135
1175
* @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>
1136
1184
* @static
1137
1185
*/
1138
- static fetchAll ( list : Array < ParseObject > , options ) {
1186
+ static fetchAll ( list : Array < ParseObject > , options : RequestOptions ) {
1139
1187
var options = options || { } ;
1140
1188
1141
1189
var queryOptions = { } ;
@@ -1145,13 +1193,61 @@ class ParseObject {
1145
1193
if ( options . hasOwnProperty ( 'sessionToken' ) ) {
1146
1194
queryOptions . sessionToken = options . sessionToken ;
1147
1195
}
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
+ }
1148
1210
return CoreManager . getObjectController ( ) . fetch (
1149
1211
list ,
1150
1212
true ,
1151
1213
queryOptions
1152
1214
) ;
1153
1215
}
1154
1216
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
+
1155
1251
/**
1156
1252
* Fetches the given list of Parse.Object if needed.
1157
1253
* If any error is encountered, stops and calls the error handler.
@@ -1570,6 +1666,9 @@ var DefaultController = {
1570
1666
}
1571
1667
var query = new ParseQuery ( className ) ;
1572
1668
query . containedIn ( 'objectId' , ids ) ;
1669
+ if ( options && options . include ) {
1670
+ query . include ( options . include ) ;
1671
+ }
1573
1672
query . _limit = ids . length ;
1574
1673
return query . find ( options ) . then ( ( objects ) => {
1575
1674
var idMap = { } ;
@@ -1604,10 +1703,14 @@ var DefaultController = {
1604
1703
} ) ;
1605
1704
} else {
1606
1705
var RESTController = CoreManager . getRESTController ( ) ;
1706
+ const params = { } ;
1707
+ if ( options && options . include ) {
1708
+ params . include = options . include . join ( ) ;
1709
+ }
1607
1710
return RESTController . request (
1608
1711
'GET' ,
1609
1712
'classes/' + target . className + '/' + target . _getId ( ) ,
1610
- { } ,
1713
+ params ,
1611
1714
options
1612
1715
) . then ( ( response , status , xhr ) => {
1613
1716
if ( target instanceof ParseObject ) {
0 commit comments