Attribute
Attributes decorate fields and models and attach extra behaviors or constraints to them.
ZModel's standard library provides a set of predefined attributes, plugins can provide additional attributes, and you can also define your own attributes in the schema.
Syntax​
Field attribute​
Definition​
Field attribute name is prefixed by a single @
.
attribute NAME(PARAMS)
-
NAME
Attribute name. Field attribute's name must start with '@'.
-
PARAMS
Attribute parameters. See Parameters for details.
Example:
attribute @id(map: String?, length: Int?)
Application​
id String ATTR_NAME(ARGS)?
-
ATTR_NAME
Attribute name.
-
ARGS
Argument list. See Parameters for details.
Example:
model User {
id Int @id(map: "_id")
}
Model attribute​
Definition​
Field attribute name is prefixed by double @@
.
attribute @@NAME(PARAMS)
-
NAME
Attribute name. Model attribute's name must start with '@@'.
-
PARAMS
Attribute parameters. See Parameters for details.
Example:
attribute @@unique(_ fields: FieldReference[], name: String?, map: String?)