Wiki

Clone wiki

Marshmallow / Attributes

Attributes are used to decorate PODO's and describe it's properties. They are declared in Mapping.Attributes unit. Some used attributes will be explained here.

[Entity]

Should be used only in the entity type declaration. Shows that class will be used by ORM when building database schema.


[Table(const ATablename: string; const ASchema: string = '')]

Should be used only in the entity type declaration. Can optionally specify table name and schema.


[AutoGenerated]

Must be set on auto increment (identity) columns so that the framework can fetch it's value after it saved it's data to the database.


[Sequence(const ASeqName: string; AInitValue: NativeInt; AIncrement: Integer)]

Should be used only in the entity type declaration. Used for generator columns.


[OneToMany(ARequired: Boolean; ACascade: TCascadeTypes)]

Specifies that property or field contains many values (list) which are lazy loaded. AMappedBy must contain primary key column property or field name.


[ManyToOne(ARequired: Boolean; ACascade: TCascadeTypes; const AMappedBy: string)]

Specifies that property or field contains one value (model). AMappedBy must contain primary key column property or field name.


[ForeignJoinColumn(const AName: string; const AReferencedTableName, AReferencedColumnName: string; AForeignStrategies: TForeignStrategies)]

Specifies that property or field is foreign key column in the database table. AName - column's name in the database. AReferencedTableName - referenced table name. AReferencedColumnName - referenced column name.


[Column(const AName: string; AProperties: TColumnProperties; ALength: Integer; APrecision: Integer; AScale: Integer; const ADescription: string)]

Probably the most popular attribute. It is used to set additional column properties.


[Version]

Can be used to implement offline optimistic locking for the entity. If this attribute is set and the entity has been changed elsewhere, the EORMOptimisticLockException will be raise when trying to save the entity.


[Query(const AQueryText: string)]

Represents query which should be used for given repository method.

Updated