About aurelius-mapping
aurelius-mapping is a mapping guide for Delphi developers using TMS Aurelius to map classes to relational databases. It covers automapping, explicit attributes, and entity lifetime rules for associations and collections.
Key features
- 01Use automapping for new schemas
- 02Use explicit attributes for legacy schemas
- 03Override mapping defaults selectively
- 04Manage association and collection lifetimes
- 05Register entities to prevent linker removal
Use cases
- 01Map Delphi classes to a new schema
- 02Match existing table and column names
- 03Configure lazy associations and collections
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ tmssoftware/ skills --skill aurelius-mappingAfter installing, type/aurelius-mappingin Claude Code to confirm it loaded.
Bundled filesreferences/mapping.md
Details
From the project READMEAurelius Mapping
Map Delphi classes to a relational database using TMS Aurelius attributes. All attributes are declared in unit Aurelius.Mapping.Attributes.
Read references/mapping.md for all attribute syntax, options tables, and code examples. The guidance below covers decisions and rules that the reference does not emphasize.
Approach
New schema (no existing tables): Default to [Automapping]. It infers table names, column names, nullability, and the identifier from field naming conventions, requiring no extra attributes for simple cases.
Legacy or fixed schema: Use explicit attributes ([Table], [Column], [Id], etc.) to match the existing column and table names exactly.
Mixed: Automapping is not all-or-nothing — add explicit attributes only where the defaults need to be overridden.
When the user hasn't specified, ask or infer from context (existing table definitions → explicit; greenfield → automapping).
Critical Rules
These are the most common mistakes. Apply them without exception.
Object lifetime — associations
- Never create or free a many-to-one associated object in the parent's constructor or destructor. Aurelius owns the lifetime of associated entity objects.
- Use plain
Tfield type for eager associations; useProxy<T>field type for lazy associations. - Expose lazy associations through a property that returns
FArtist.Value.
Object lifetime — collections
- Do create and free the
TList<T>container in the parent's constructor and destructor. - Never create or free the child entity objects inside the list — Aurelius manages them.
- Do not use
TObjectList<T>withOwnsObjects = True. - For lazy collections, use
Proxy<TList<T>>as the field type. UseSetInitialValue/DestroyValueinstead of accessing.Valuein constructor/destructor.
Registering entities
Always add RegisterEntity calls in the initialization section of the unit:
initialization
RegisterEntity(TCustomer);
RegisterEntity(TCountry);
This prevents the Delphi linker from removing the class. It is especially important in server applications (XData services) where entity classes may not be directly referenced in code.
Reference
For all attribute signatures, options, and full code examples, read references/mapping.md.
The reference covers: basic entity mapping, automapping rules and overrides, abstract entities, nullable fields, blob fields, many-to-one associations (eager and lazy), one-to-many associations (bidirectional and unidirectional, eager and lazy), collection ordering and filtering, foreign key naming, single-table and joined-tables inheritance, composite identifiers.