Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -84,7 +84,7 @@ a.schema({
User: a.model({
lastKnownLocation: a.ref('Location'),
}),
});
}).authorization((allow) => allow.publicApiKey());
```

<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android", "flutter"]}>
Expand Down Expand Up @@ -131,7 +131,7 @@ a.schema({
privacySetting: a.enum(['PRIVATE', 'FRIENDS_ONLY', 'PUBLIC']),
content: a.string(),
}),
});
}).authorization((allow) => allow.publicApiKey());
```

Long-form approach
Expand All @@ -152,7 +152,7 @@ a.schema({
Video: a.model({
privacySetting: a.ref('PrivacySetting'),
}),
});
}).authorization((allow) => allow.publicApiKey());
```

<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android", "flutter"]}>
Expand Down Expand Up @@ -206,7 +206,7 @@ const schema = a.schema({
Todo: a.model({
content: a.string().required(),
}),
});
}).authorization((allow) => allow.publicApiKey());
```

## Mark fields as arrays
Expand All @@ -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
Expand All @@ -231,7 +231,7 @@ const schema = a.schema({
Todo: a.model({
content: a.string().default('My new Todo'),
}),
});
}).authorization((allow) => allow.publicApiKey());
```
<Callout>
**Note:** The `.default(...)` modifier can't be applied to required fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -951,5 +949,5 @@ const schema = a.schema({
authoredPosts: a.hasMany('Post', 'authorId'),
// highlight-end
}),
})
}).authorization(allow => [allow.publicApiKey()]);
```