tempest-framework icon indicating copy to clipboard operation
tempest-framework copied to clipboard

Optional ids in ORM

Open brendt opened this issue 10 months ago • 2 comments

The model query builders currently assume there's always an Id field on model classes. This assumption should be made optional, because Ids aren't actually required by the database

brendt avatar Mar 26 '25 13:03 brendt

Yes, thank you. This assumption also discarded the fact that many RDBMS support compound primary keys.

innocenzi avatar Mar 26 '25 15:03 innocenzi

The framework may still need to make the id "assumption" somehow for tracking relationships and whatnot if not specified otherwise.

I propose we add a Key and/or PrimaryKey attributes. One for the class, which would allow specifying compound primary keys and one if you just want to specify it directly on the property.

Something like:

#[PrimaryKey(['license_plate', 'state'])]
final class Car
{
    public string $licensePlate;

    public string $state;

    public string $make;

    //...
}

or

final class Book
{
    #[Key]
    public string $uuid;

    public string $title;

    //...
}

erikaraujo avatar Apr 01 '25 10:04 erikaraujo