Skip to content

Can't use primary keys that aren't auto-increment int #6

@devvoh

Description

@devvoh

For example, wanting to use UUID v6 as a primary key. What happens when you set up your entities and repositories appropriately for this? Well, it almost works, but then it breaks.

Due to the way parable-php/orm is written, for inserts, the primary key is always removed from the value set, to allow the sql flavor you're using to auto-generate it. Which, obviously, is a terrible idea when you're using custom primary keys.

There's multiple ways of approaching a fix for this, which is either specific about fixing custom primary keys, or offers a more generic way of tying into the insert process (perhaps even update, delete?).

Specific: Introduce HasCustomPrimaryKey and skip the id auto-removal upon insert if set.
Generic: Introduce beforeInsert(array $values) and possibly more. If implemented, would it just skip the default logic?

What if both?

interface HasCustomPrimaryKey {
    protected function beforeInsert(array $values): array;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions