Skip to content

annotation Athena::ORM::Annotations::GeneratedValue #

Has the database generate the value of the entity's identifier. Only has an effect alongside AORMA::ID.

@[AORMA::Column]
@[AORMA::ID]
@[AORMA::GeneratedValue]
property! id : Int64

The generated identifier is assigned to the entity when it's inserted, during AORM::EntityManager#flush. It isn't available right after AORM::EntityManager#persist.

Configuration#

Optional Arguments#

strategy#

Type: AORM::Mapping::GeneratedValueStrategy Default: :auto

How the identifier is generated:

  • :auto - Uses the strategy preferred by the database, which is :identity for every supported database.
  • :identity - The database generates the value when the row is inserted, e.g. via an AUTO_INCREMENT or GENERATED BY DEFAULT AS IDENTITY column. It's read back with RETURNING on the databases that support it, and as the last inserted ID otherwise.
  • :none - Your code assigns the identifier before persisting the entity, the same as not applying this annotation.
  • :sequence - The value is taken from a database sequence, see AORMA::SequenceGenerator.
  • :custom - The value is generated by your own code.

Todo

The :sequence and :custom strategies aren't supported yet; using them raises when the entity's metadata is built.