Skip to content

Commit 832de92

Browse files
committed
fix: Parse.Schema.addField accepts Pointer and Relation types
Closes: #1281
1 parent 3551a06 commit 832de92

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/ParseSchema.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class ParseSchema {
214214
* Valid options are:<ul>
215215
* <li>required: If field is not set, save operation fails (Requires Parse Server 3.7.0+)
216216
* <li>defaultValue: If field is not set, a default value is selected (Requires Parse Server 3.7.0+)
217+
* <li>targetClass: Required if type is Pointer or Parse.Relation
217218
* </ul>
218219
* @returns {Parse.Schema} Returns the schema, so you can chain this call.
219220
*/
@@ -226,6 +227,12 @@ class ParseSchema {
226227
if (FIELD_TYPES.indexOf(type) === -1) {
227228
throw new Error(`${type} is not a valid type.`);
228229
}
230+
if (type === 'Pointer') {
231+
return this.addPointer(name, options.targetClass, options);
232+
}
233+
if (type === 'Relation') {
234+
return this.addRelation(name, options.targetClass, options);
235+
}
229236
const fieldOptions = { type };
230237

231238
if (typeof options.required === 'boolean') {

src/__tests__/ParseSchema-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ describe('ParseSchema', () => {
9292
done();
9393
});
9494

95+
it('can create schema pointer and relation with addFields', () => {
96+
const schema = new ParseSchema('SchemaTest');
97+
schema
98+
.addField('newPointer', 'Pointer', { targetClass: '_User' })
99+
.addField('newRelation', 'Relation', { targetClass: '_User' });
100+
101+
expect(schema._fields.newPointer.type).toEqual('Pointer');
102+
expect(schema._fields.newRelation.type).toEqual('Relation');
103+
expect(schema._fields.newPointer.targetClass).toEqual('_User');
104+
expect(schema._fields.newRelation.targetClass).toEqual('_User');
105+
});
106+
95107
it('can create schema fields required and default values', () => {
96108
const object = new ParseObject('TestObject', '1234');
97109
const schema = new ParseSchema('SchemaTest');

0 commit comments

Comments
 (0)