@@ -174,25 +174,37 @@ DatabaseController.prototype.update = function(className, query, update, {
174
174
if ( acl ) {
175
175
query = addWriteACL ( query , acl ) ;
176
176
}
177
- var mongoWhere = this . transform . transformWhere (
178
- schemaController ,
179
- className ,
180
- query ,
181
- { validate : ! this . skipValidation }
182
- ) ;
183
- mongoUpdate = this . transform . transformUpdate (
184
- schemaController ,
185
- className ,
186
- update ,
187
- { validate : ! this . skipValidation }
188
- ) ;
189
- if ( many ) {
190
- return collection . updateMany ( mongoWhere , mongoUpdate ) ;
191
- } else if ( upsert ) {
192
- return collection . upsertOne ( mongoWhere , mongoUpdate ) ;
193
- } else {
194
- return collection . findOneAndUpdate ( mongoWhere , mongoUpdate ) ;
195
- }
177
+ return schemaController . getOneSchema ( className )
178
+ . catch ( error => {
179
+ // If the schema doesn't exist, pretend it exists with no fields. This behaviour
180
+ // will likely need revisiting.
181
+ if ( error === undefined ) {
182
+ return { fields : { } } ;
183
+ }
184
+ throw error ;
185
+ } )
186
+ . then ( parseFormatSchema => {
187
+ var mongoWhere = this . transform . transformWhere (
188
+ schemaController ,
189
+ className ,
190
+ query ,
191
+ { validate : ! this . skipValidation } ,
192
+ parseFormatSchema
193
+ ) ;
194
+ mongoUpdate = this . transform . transformUpdate (
195
+ schemaController ,
196
+ className ,
197
+ update ,
198
+ { validate : ! this . skipValidation }
199
+ ) ;
200
+ if ( many ) {
201
+ return collection . updateMany ( mongoWhere , mongoUpdate ) ;
202
+ } else if ( upsert ) {
203
+ return collection . upsertOne ( mongoWhere , mongoUpdate ) ;
204
+ } else {
205
+ return collection . findOneAndUpdate ( mongoWhere , mongoUpdate ) ;
206
+ }
207
+ } ) ;
196
208
} )
197
209
. then ( result => {
198
210
if ( ! result ) {
@@ -322,7 +334,22 @@ DatabaseController.prototype.destroy = function(className, query, { acl } = {})
322
334
if ( acl ) {
323
335
query = addWriteACL ( query , acl ) ;
324
336
}
325
- return this . adapter . deleteObjectsByQuery ( className , query , schemaController , ! this . skipValidation )
337
+ return schemaController . getOneSchema ( className )
338
+ . catch ( error => {
339
+ // If the schema doesn't exist, pretend it exists with no fields. This behaviour
340
+ // will likely need revisiting.
341
+ if ( error === undefined ) {
342
+ return { fields : { } } ;
343
+ }
344
+ throw error ;
345
+ } )
346
+ . then ( parseFormatSchema => this . adapter . deleteObjectsByQuery (
347
+ className ,
348
+ query ,
349
+ schemaController ,
350
+ ! this . skipValidation ,
351
+ parseFormatSchema
352
+ ) )
326
353
. catch ( error => {
327
354
// When deleting sessions while changing passwords, don't throw an error if they don't have any sessions.
328
355
if ( className === "_Session" && error . code === Parse . Error . OBJECT_NOT_FOUND ) {
@@ -627,18 +654,29 @@ DatabaseController.prototype.find = function(className, query, {
627
654
if ( ! isMaster ) {
628
655
query = addReadACL ( query , aclGroup ) ;
629
656
}
630
- let mongoWhere = this . transform . transformWhere ( schemaController , className , query ) ;
631
- if ( count ) {
632
- delete mongoOptions . limit ;
633
- return collection . count ( mongoWhere , mongoOptions ) ;
634
- } else {
635
- return collection . find ( mongoWhere , mongoOptions )
636
- . then ( ( mongoResults ) => {
637
- return mongoResults . map ( ( r ) => {
638
- return this . untransformObject ( schemaController , isMaster , aclGroup , className , r ) ;
657
+ return schemaController . getOneSchema ( className )
658
+ . catch ( error => {
659
+ // If the schema doesn't exist, pretend it exists with no fields. This behaviour
660
+ // will likely need revisiting.
661
+ if ( error === undefined ) {
662
+ return { fields : { } } ;
663
+ }
664
+ throw error ;
665
+ } )
666
+ . then ( parseFormatSchema => {
667
+ let mongoWhere = this . transform . transformWhere ( schemaController , className , query , parseFormatSchema ) ;
668
+ if ( count ) {
669
+ delete mongoOptions . limit ;
670
+ return collection . count ( mongoWhere , mongoOptions ) ;
671
+ } else {
672
+ return collection . find ( mongoWhere , mongoOptions )
673
+ . then ( ( mongoResults ) => {
674
+ return mongoResults . map ( ( r ) => {
675
+ return this . untransformObject ( schemaController , isMaster , aclGroup , className , r ) ;
676
+ } ) ;
639
677
} ) ;
640
- } ) ;
641
- }
678
+ }
679
+ } ) ;
642
680
} ) ;
643
681
} ) ;
644
682
} ;
0 commit comments