Use when defining ROM Struct attributes, configuring dry-types coercion for entity fields, implementing value-based equality semantics, or setting up a domain model class in Hanami 2.x. Handles creating entity classes, declaring typed attributes, enforcing immutability, configuring the repository struct namespace, and syncing entity definitions with schema changes. Use when working with ROM entity class definitions, persistence layer value objects, ROM relation mappings, or any Hanami 2.x domain model backed by rom-rb.
Use when defining ROM Struct attributes, configuring dry-types coercion for entity fields, implementing value-based equality semantics, or setting up a domain model class in Hanami 2.x. Handles creating entity classes, declaring typed attributes, enforcing immutability, configuring the repository struct namespace, and syncing entity definitions with schema changes. Use when working with ROM entity class definitions, persistence layer value objects, ROM relation mappings, or any Hanami 2.x domain model backed by rom-rb.
Apply dry-types coercion and constraints:
Specify attribute types using standard dry-types constraints. For a comprehensive list of type modifiers, constraints, and defaults, see TYPES.md.
Entities are immutable:
Entities cannot be mutated in place. Use #copy to return a new instance with updated attributes:
updated_user = user.copy(first_name:"Alicia")
Equality is value-based:
Two entity instances with identical attributes are considered equivalent:
user1 == user2 # => true if attributes match
Register the Entity namespace in Repositories:
Wired repositories require mapping directives to output typed Entity classes rather than generic ROM structs:
Sync Entities with migrations:
Keep entity class attributes manually updated with database schema modifications. Verify using the Hanami console or spec suite: