amplication / docs

Amplication docs
https://docs.amplication.com
Apache License 2.0
17 stars 62 forks source link

📖Documentation: Prisma Custom attributes on entity and fields #289

Closed GreenMachine01 closed 1 year ago

GreenMachine01 commented 1 year ago

https://github.com/amplication/amplication/issues/5989 https://github.com/amplication/amplication/issues/5990

Image

GreenMachine01 commented 1 year ago

From ChatGPT:

Custom Attributes on Entities and Fields Custom attributes are a powerful feature that provides you with the flexibility to add additional metadata or functionality to your entities and fields. They allow for a higher level of customization and control, enabling you to tailor the behavior of your entities and fields to best fit your specific needs.

Adding Custom Attributes to Entities You can add custom attributes to entities by using a simple command format: '@@command([parameters])'.

In this command, replace 'command' with the operation you wish to perform (e.g., 'map'), and 'parameters' with the parameters required for your chosen operation.

For example, if you wanted to create a mapping for an entity named 'users', your command would look like this: '@@map('users')'.

Adding Custom Attributes to Fields Similarly, you can also add custom attributes to fields using a similar command format: '@command([parameters])'.

In this format, replace 'command' with your desired operation (e.g., 'index'), and 'parameters' with the appropriate parameters for that operation.

As an example, if you wanted to index a field named 'username', you would use the following command: '@index('username')'.

Notes

Custom attributes offer an efficient and effective way to enhance your data structure, enabling you to optimize the way you manage, search, and interact with your data. With this feature, you can build systems that are more streamlined, adaptable, and aligned with your unique needs.

mulygottlieb commented 1 year ago

Please see the relevant prisma documentation: https://www.prisma.io/docs/concepts/components/prisma-schema/data-model

And in particular these sub-sections:

https://www.prisma.io/docs/concepts/components/prisma-schema/data-model#defining-attributes

https://www.prisma.io/docs/concepts/components/prisma-schema/data-model#native-types-mapping

https://www.prisma.io/docs/concepts/components/prisma-schema/data-model#mapping-model-names-to-tables-or-collections

abrl91 commented 1 year ago

entity field attributes:

NOTE: There are field attributes such as fields: [fieldName], references: [referenceField] and @unique that we already add when a relation is set or the toggle is on

Screenshot 2023-05-23 at 16 57 24

Therefore, the user should be aware of not adding relation attribute where we already added, or add the relation at the other side and then his/her prisma schema will not be valid

model field attributes:

image


And the results: image

dericksozo commented 1 year ago

This one is taken care of in #310.