Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
devvoh opened this issue Apr 16, 2022 · 0 comments
Open

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

devvoh opened this issue Apr 16, 2022 · 0 comments

Comments

@devvoh
Copy link

devvoh commented Apr 16, 2022

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant