Skip to content

Commit a926712

Browse files
committed
Start using parse format schema in transformQueryKeyValue
1 parent 5f564f3 commit a926712

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

spec/Schema.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ describe('SchemaController', () => {
124124
var obj;
125125
createTestUser()
126126
.then(user => {
127-
console.log(user);
128127
return config.database.loadSchema()
129128
// Create a valid class
130129
.then(schema => schema.validateObject('Stuff', {foo: 'bar'}))

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ function transformQueryKeyValue(schema, className, key, value, { validate } = {}
168168
if (!(value instanceof Array)) {
169169
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $or format - use an array value');
170170
}
171-
return {key: '$or', value: value.map(subQuery => transformWhere(schema, className, subQuery, parseFormatSchema))};
171+
return {key: '$or', value: value.map(subQuery => transformWhere(schema, className, subQuery, {}, parseFormatSchema))};
172172
case '$and':
173173
if (!(value instanceof Array)) {
174174
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $and format - use an array value');
175175
}
176-
return {key: '$and', value: value.map(subQuery => transformWhere(schema, className, subQuery, parseFormatSchema))};
176+
return {key: '$and', value: value.map(subQuery => transformWhere(schema, className, subQuery, {}, parseFormatSchema))};
177177
default:
178178
// Other auth data
179179
const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
@@ -187,18 +187,19 @@ function transformQueryKeyValue(schema, className, key, value, { validate } = {}
187187
}
188188
}
189189

190-
let expected = undefined;
191-
if (schema && schema.getExpectedType) {
192-
expected = schema.getExpectedType(className, key);
193-
}
194-
if ((expected && expected.type == 'Pointer') ||
195-
(!expected && value && value.__type == 'Pointer')) {
196-
key = '_p_' + key;
197-
}
198190
const expectedTypeIsArray =
199191
parseFormatSchema &&
200192
parseFormatSchema.fields[key] &&
201-
parseFormatSchema.fields[key].type === 'Array'
193+
parseFormatSchema.fields[key].type === 'Array';
194+
195+
const expectedTypeIsPointer =
196+
parseFormatSchema &&
197+
parseFormatSchema.fields[key] &&
198+
parseFormatSchema.fields[key].type === 'Pointer';
199+
200+
if (expectedTypeIsPointer || !parseFormatSchema && value && value.__type === 'Pointer') {
201+
key = '_p_' + key;
202+
}
202203

203204
// Handle query constraints
204205
if (transformConstraint(value, expectedTypeIsArray) !== CannotTransform) {

0 commit comments

Comments
 (0)