struct Athena::ORM::Mapping::DefaultNamingStrategy
inherits Struct
#
The naming strategy used for every entity.
It derives names from the unqualified class names and property names:
- A column is named after its property, e.g.
created_at. - A to-one join column is named
<property>_id, and references the target'sidcolumn. - A many-to-many join table is named
<source>_<target>using the underscored class names, e.g.user_groupforUser#groups. - The join table's columns are named
<class>_idusing the underscored class names, e.g.user_idandgroup_id, and reference theidcolumns.
The table of an entity defaults to its underscored class name, e.g. user_profile for App::UserProfile.
@[AORMA::Entity]
class User < AORM::Entity
# Mapped to the `display_name` column of the `user` table.
@[AORMA::Column]
property! display_name : String
# Mapped to the `avatar_id` join column, referencing `avatar.id`.
@[AORMA::OneToOne]
property avatar : Avatar? = nil
# Mapped through the `user_group` join table, with the `user_id` and `group_id` columns.
@[AORMA::ManyToMany]
property groups : AORM::Collection(Group) = AORM::ArrayCollection(Group).new
# ...
end
Included modules
Athena::ORM::Mapping::NamingStrategyInterface
Constructors#
Methods#
#join_column_name(property_name : String, entity_class : AORM::Entity.class) : String#
Returns the join column name of the to-one association property named property_name of entity_class.
#join_key_column_name(entity_name : String, referenced_column_name : String | Nil) : String#
Returns the name of a join table column referencing the entity with the unqualified class name entity_name.
#join_table_name(source_entity : String, target_entity : String, property_name : String | Nil) : String#
Returns the name of the join table of a many-to-many association from source_entity to target_entity, given their unqualified class names.
#property_to_column_name(property_name : String, entity_class : AORM::Entity.class) : String#
Returns the column name for the property named property_name of entity_class.
#reference_column_name : String#
Returns the name of the column join columns reference by default.