Add properties to an entity
Properties are the characteristics of your entities. For example, a Product can have properties like name
, description
, price
...
Syntax
You can add the properties to your entities in the backend.yml file
name: Blog about cats
entities:
📝 Post:
properties:
- name # Short syntax for string type.
- { name: content, type: text } # Property type specified.
- { name: publishedAt, type: date }
- { name: authorEmail, type: email, hidden: true } # Extra options.
Property params
You can pass arguments using the long syntax:
Option | Default | Type | Description |
---|---|---|---|
type | "string" | PropType | The Property type (text, number, email, location...) |
hidden | false | boolean | If the property should be hidden in the API response |
options | Object | Specific options depending on type |
Property types
Each property has a type that represents real-world usages. Some of them have specific options.
String
A simple string.
- { name: firstName, type: string }
# Short syntax, same as above.
- firstName
Textarea
Textarea field for medium-size texts.
- { name: description, type: text }
Number
A numerical value.
- { name: age, type: number }
Link
An URL that links to an external page.
- { name: website, type: link }
Money
A money field with a currency.
- { name: price, type: money, options: { currency: 'EUR' } }
Parameters
Option | Default | Type | Description |
---|---|---|---|
currency | USD | string | ISO 4217 currency code |
Date
Basic date field.
- { name: startDate, type: date }
Timestamp
Timestamp field.
- { name: acquiredAt, type: timestamp }
Email
- { name: email, type: email }
Boolean
For any field with a "true or false" value.
- { name: isActive, type: boolean }
Password
Password field.
- { name: password, type: password }
Caution
Passwords should never be stored as clear text.
Choice
A given choice of options.
- { name: sex, type: choice, options: { values: [male, female] } }
# Sequential if the values are ordered in a logical sense..
- {
name: status,
type: choice,
options: { values: [draft, submitted, published], sequential: true }
}
Parameters
Option | Default | Type | Description |
---|---|---|---|
values | (empty) | String[] | An array of strings representing the available choices |
sequential | false | boolean | Specifies if the values are ordered in a logical sense |
Location
The location type consists in a object with lat
and lng
coordinates.
- { name: location, type: location }