annotation Athena::ORM::Annotations::OneToMany
#
Maps an instance variable to the collection of entities on the many side of a one-to-many association.
It's the inverse side of a AORMA::ManyToOne association, which holds the foreign key column.
@[AORMA::Entity]
class Product < AORM::Entity
# ...
@[AORMA::OneToMany(mapped_by: "product")]
property features : AORM::Collection(Feature) = AORM::ArrayCollection(Feature).new
end
@[AORMA::Entity]
class Feature < AORM::Entity
# ...
@[AORMA::ManyToOne(inversed_by: "features")]
property product : Product? = nil
end
The target entity is inferred from the collection's type.
The collection is loaded the first time it's used, with a SELECT on the target's table filtered by the foreign key column.
Since it's the inverse side, adding or removing elements doesn't change anything in the database; set the owning AORMA::ManyToOne side of each element instead.
Todo
A unidirectional one-to-many association via a join table isn't supported yet.
Use a AORMA::ManyToMany association instead.
Configuration#
Required Arguments#
mapped_by#
Type: String
The name of the AORMA::ManyToOne property on the target entity.
Omitting it raises when the entity's metadata is built.
Optional Arguments#
cascade#
Type: Array(String)? Default: nil
The operations on this entity that are also applied to the entities in the collection, see the associations section of the manual.
One or more of "persist", "remove", "detach", or "all".
orphan_removal#
Type: Bool Default: false
Whether entities removed from the collection are removed from the database.
It also implies the "remove" cascade.
target_entity#
Type: AORM::Entity.class? Default: the collection's type argument
The class of the associated entities, if it can't be inferred from the instance variable's type.
fetch_mode#
Type: AORM::Mapping::FetchMode Default: :lazy
When the collection is loaded.
Todo
Not supported yet; it's ignored, and collections are always loaded lazily.
index_by#
Type: String? Default: nil
The field of the target entity the collection is indexed by.
Todo
Not supported yet; it's ignored.