Skip to content

feat(orm): support assigning generated IDs to Entity objects #488

Description

@GaspardKirira

Summary

Add an explicit repository operation that assigns a generated database identifier back to an entity implementing vix::orm::Entity.

Current behavior

BaseRepository<T>::create(const T&) returns the generated identifier but cannot modify the passed object.

Entity::setId() exists, but the repository does not currently use it.

Users must manually call setId() after insertion.

Expected behavior

The ORM should provide an explicit operation that inserts an entity and assigns the generated ID when the entity supports it.

The existing create(const T&) behavior must remain unchanged.

Scope

  • Add a source-compatible entity-aware creation method.
  • Detect entities derived from vix::orm::Entity.
  • Assign the generated identifier through setId().
  • Preserve the returned identifier.
  • Handle identifiers outside the signed 64-bit range safely.
  • Add SQLite integration tests.
  • Update the entity identity example.
  • Document the behavior.

Suggested API direction

A possible method name is createAndAssign().

The final method name should be reviewed before implementation.

Suggested files

  • modules/orm/include/vix/orm/Repository.hpp
  • modules/orm/include/vix/orm/Entity.hpp
  • modules/orm/tests/entity_identity_test.cpp
  • modules/orm/examples/15_entity_identity.cpp

Acceptance criteria

  • Existing create(const T&) remains unchanged.
  • The new operation inserts the entity.
  • The generated ID is assigned through setId().
  • The generated ID is also returned.
  • Non-Entity types continue to work with existing APIs.
  • Identifier overflow is handled clearly.
  • SQLite integration tests pass.

Non-goals

This issue does not include:

  • automatic entity persistence;
  • dirty tracking;
  • identity maps;
  • non-integer generated identifiers.

Suggested labels

  • scope:orm
  • type:feature
  • tests
  • good first issue
  • status:accepted

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions