File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -214,6 +214,7 @@ class ParseSchema {
214
214
* Valid options are:<ul>
215
215
* <li>required: If field is not set, save operation fails (Requires Parse Server 3.7.0+)
216
216
* <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
217
218
* </ul>
218
219
* @returns {Parse.Schema } Returns the schema, so you can chain this call.
219
220
*/
@@ -226,6 +227,12 @@ class ParseSchema {
226
227
if ( FIELD_TYPES . indexOf ( type ) === - 1 ) {
227
228
throw new Error ( `${ type } is not a valid type.` ) ;
228
229
}
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
+ }
229
236
const fieldOptions = { type } ;
230
237
231
238
if ( typeof options . required === 'boolean' ) {
Original file line number Diff line number Diff line change @@ -92,6 +92,18 @@ describe('ParseSchema', () => {
92
92
done ( ) ;
93
93
} ) ;
94
94
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
+
95
107
it ( 'can create schema fields required and default values' , ( ) => {
96
108
const object = new ParseObject ( 'TestObject' , '1234' ) ;
97
109
const schema = new ParseSchema ( 'SchemaTest' ) ;
You can’t perform that action at this time.
0 commit comments