class Athena::ORM::Events::PrePersistEventArgs(T)
inherits Athena::ORM::Events::LifecycleEventArgs
#
Emitted when a new entity is persisted, before it's scheduled for insertion.
That happens when the entity is passed to AORM::EntityManager#persist, when the persist cascades to it from an association mapped with cascade: ["persist"], or when a flush finds it through such an association.
It's only emitted the first time an entity is persisted, not on later flushes.
Lifecycle callbacks annotated with AORMA::PrePersist receive it.
@[AORMA::Entity]
class Article < AORM::Entity
# ...
@[AORMA::PrePersist]
def set_created_at : Nil
@created_at = Time.utc
end
end
Note
Identifiers generated by the database, such as with AORMA::GeneratedValue, aren't available yet.