class Athena::ORM::Mapping::Class(T)
inherits Reference
#
The mapping metadata of the entity class T: its table, the column each field is mapped to, its associations, and its identifier.
The metadata is built from the entity's annotations the first time an entity manager needs it, and is then reused by that entity manager.
Entity managers can also share it through a AORM::Mapping::MetadataCache, as those created by an AORM::EntityManagerFactory do.
Building it raises if the mapping is invalid, such as a field whose Crystal type has no column type mapped to it.
@[AORMA::Entity]
@[AORMA::Table(name: "users")]
class User < AORM::Entity
@[AORMA::Column]
@[AORMA::ID]
@[AORMA::GeneratedValue]
property! id : Int64
@[AORMA::Column(name: "user_name")]
property! username : String
end
metadata = em.class_metadata User
metadata.table_name # => "users"
metadata.identifier # => Set{"id"}
metadata.column_name "username" # => "user_name"
metadata.field_mappings["username"].type # => "string"
Included modules
Athena::ORM::Mapping::ClassInterface
Methods#
#association_mappings : Hash(String, Association)#
Returns the mappings of the association properties, keyed by property name.
#column_name(field_name : String) : String#
Returns the column name of the field named field_name, without quotes. Returns field_name itself if it isn't mapped to a column.
#custom_repository_class : AORM::RepositoryInterface.class | Nil#
The repository class returned by AORM::EntityManager#repository for this entity, as set by AORMA::Entity(repository_class: ...).
nil when the entity uses the default AORM::EntityRepository.
#custom_repository_class=(custom_repository_class : AORM::RepositoryInterface.class | Nil)#
The repository class returned by AORM::EntityManager#repository for this entity, as set by AORMA::Entity(repository_class: ...).
nil when the entity uses the default AORM::EntityRepository.
#field_mappings : Hash(String, Field)#
Returns the mappings of the fields mapped to a column with AORMA::Column, keyed by property name.
#field_names : Hash(String, String)#
Maps each column name to the name of the field mapped to it.
#id_generator_type : AORM::Mapping::GeneratedValueStrategy#
How the values of the identifier are generated.
AUTO is resolved to the platform's preferred strategy when the metadata is built.
#id_generator_type=(id_generator_type : AORM::Mapping::GeneratedValueStrategy)#
How the values of the identifier are generated.
AUTO is resolved to the platform's preferred strategy when the metadata is built.
#identifier_identity? : Bool#
Returns whether the database generates the identifier values when inserting rows.
#identifier_natural? : Bool#
Returns whether the identifier values are assigned by your code, rather than generated.
#inheritance_type : InheritanceType#
Returns the kind of inheritance mapping the entity uses.
Todo
Inheritance mapping isn't supported yet, so this is always NONE.
#is_identifier?(field_name : String) : Bool#
Returns whether the field named field_name is part of the identifier.
ameba:disable Naming/PredicateName
#is_identifier_composite : Bool#
Whether the identifier is made up of more than one field.
#read_only=(read_only : Bool)#
Whether the entity is read-only, as set by AORMA::Entity(read_only: true).
Changes to managed instances of a read-only entity aren't written on flush, although they can still be inserted and removed.
#read_only? : Bool#
Whether the entity is read-only, as set by AORMA::Entity(read_only: true).
Changes to managed instances of a read-only entity aren't written on flush, although they can still be inserted and removed.
#single_identifier_column_name : String#
Returns the column name of the identifier field.
Raises if the identifier is composite, or the entity has no identifier.
#single_identifier_field_name : String#
Returns the name of the identifier field.
Raises if the identifier is composite, or the entity has no identifier.
#table_name : String#
Returns the name of the entity's table, without quotes.
Defaults to the underscored class name, e.g. user_profile for App::UserProfile, unless set with AORMA::Table.
#type_of_field(field_name : String) : String | Nil#
Returns the name of the AORM::Types::Type of the field named field_name, or nil if it isn't mapped to a column.