diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx index 334dbcb5326..37d008a8cdf 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx @@ -64,7 +64,7 @@ a.schema({ }), content: a.string(), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` **Explicit definition:** Specify the "Location" as `a.customType()` in your schema. To use the custom type, reference it through `a.ref()` in the respective field definitions. @@ -84,7 +84,7 @@ a.schema({ User: a.model({ lastKnownLocation: a.ref('Location'), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` @@ -131,7 +131,7 @@ a.schema({ privacySetting: a.enum(['PRIVATE', 'FRIENDS_ONLY', 'PUBLIC']), content: a.string(), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` Long-form approach @@ -152,7 +152,7 @@ a.schema({ Video: a.model({ privacySetting: a.ref('PrivacySetting'), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` @@ -206,7 +206,7 @@ const schema = a.schema({ Todo: a.model({ content: a.string().required(), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` ## Mark fields as arrays @@ -219,7 +219,7 @@ const schema = a.schema({ content: a.string().required(), notes: a.string().array(), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` ## Assign default values for fields @@ -231,7 +231,7 @@ const schema = a.schema({ Todo: a.model({ content: a.string().default('My new Todo'), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` **Note:** The `.default(...)` modifier can't be applied to required fields. diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx index e7d030c32fd..7e3934edfcf 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx @@ -62,17 +62,15 @@ const schema = a.schema({ teamId: a.id(), // 2. Create a belongsTo relationship with the reference field team: a.belongsTo('Team', 'teamId'), - }) - .authorization(allow => [allow.publicApiKey()]), + }), Team: a.model({ mantra: a.string().required(), // 3. Create a hasMany relationship with the reference field // from the `Member`s model. members: a.hasMany('Member', 'teamId'), - }) - .authorization(allow => [allow.publicApiKey()]), -}); + }), +}).authorization((allow) => allow.publicApiKey()); ``` ### Create a "Has Many" relationship between records @@ -464,7 +462,7 @@ const schema = a.schema({ // from the Cart model activeCart: a.hasOne('Cart', 'customerId') }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` ### Create a "Has One" relationship between records @@ -832,7 +830,7 @@ const schema = a.schema({ // highlight-next-line posts: a.hasMany('PostTag', 'tagId'), }), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ``` ## Model multiple relationships between two models @@ -858,7 +856,7 @@ const schema = a.schema({ authoredPosts: a.hasMany('Post', 'authorId'), // highlight-end }), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ``` On the client-side, you can fetch the related data with the following code: @@ -921,7 +919,7 @@ const schema = a.schema({ authoredPosts: a.hasMany('Post', ['authorName', 'authorDoB']), // highlight-next-line }).identifier(['name', 'dateOfBirth']), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ``` ## Make relationships required or optional @@ -951,5 +949,5 @@ const schema = a.schema({ authoredPosts: a.hasMany('Post', 'authorId'), // highlight-end }), -}) +}).authorization((allow) => allow.publicApiKey()); ```