Skip to main content
Version: 3.0 Alpha

Attribute

Attributes allow you to attach metadata to models and fields. As you've seen in the previous sections, they are used for many purposes, like adding unique constraints, mapping names, etc. Attributes are also indispensable for modeling relations between models.

Naming conventions

By convention, attributes attached to models use a double @@ prefix, while those for fields use a single @ prefix.

model User {
id Int @id
email String @unique

@@index([email, name])
}

Defining and applying attributes

🔋 ZModel vs Prisma Schema

Prisma schema doesn't allow users to define custom attributes, while ZModel allows it and uses it as a key mechanism for extensibility.

ZModel comes with a rich set of attributes that you can use directly. See ZModel Language Reference for a complete list. You can also define your own custom attributes for specific purposes. Attributes are defined with a list of typed parameters. Parameters can named (default) or positional. Positional parameters can be passed with or without an explicit name. Parameters can also be optional.

Here's an example for how the @unique attribute is defined:

attribute @unique(map: String?, length: Int?, sort: SortOrder?)

You can apply it in various ways:

model Foo {
x String @unique() // default application
y String @unique('y_unique') // positional parameter
z String @unique(map: 'z_unique', length: 10) // named parameter
}
Comments
Feel free to ask questions, give feedback, or report issues.

Don't Spam


You can edit/delete your comments by going directly to the discussion, clicking on the 'comments' link below