Skip to content

Commit

Permalink
(docs): Creating a page for `How To Set Default Value on Entity Field…
Browse files Browse the repository at this point in the history
…s` in the How To section.
  • Loading branch information
dericksozo committed Sep 20, 2023
1 parent ae4d40a commit 84cbfdb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions docs/how-to/default-value-entity-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: How To Set Default Value on Entity Fields
sidebar_label: Set Default Value for an Entity Field
slug: /how-to/set-default-value-entity-field
---

# How To Set Default Value on Entity Fields

Setting default values for your entity fields in Amplication is straightforward using the `@default()` custom Prisma attribute.
This can be helpful in scenarios where you want certain fields to have a predefined value when new records are created.

This guide will walk you through the steps to achieve this with various examples.

![Default Custom Prisma Attribute](./assets/default-custom-attribute.png)

## Steps to Set a Default Value:

1. Navigate to your service's _Entity Overview_ page.
2. Click on the specific _Entity_ field you want to set a default value for.
3. On the Entity Field page, you will find a text box labeled **Custom Attributes**. Here, you'll enter the custom prisma @default() attribute.
4. In the Custom Attribute text field, enter the `@default()` attribute followed by the desired default value in parentheses.
5. After entering the default value, it will be saved automatically.

## Examples

For example, to set a default string value of "DefaultText", you would enter:

```
@default("DefaultText")
```

For numeric fields, simply enter the number without quotes:

```
@default(5)
```

:::tip
Refer to [Prisma's documentation](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#default) for a full list of the values that Prisma gives you access to for the `@default()` custom attribute.
:::
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const sidebars = {
"how-to/how-to-create-service",
"how-to/how-to-create-entity",
"how-to/how-to-create-entity-field",
"how-to/default-value-entity-field",
"how-to/import-prisma-schema",
"getting-started/how-prisma-schema-is-converted-into-entities",
"how-to/erd-view-for-amplication-entities",
Expand Down

0 comments on commit 84cbfdb

Please sign in to comment.