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

Composite Keys #147

Open
matthewjumpsoffbuildings opened this issue Nov 24, 2023 · 4 comments
Open

Composite Keys #147

matthewjumpsoffbuildings opened this issue Nov 24, 2023 · 4 comments

Comments

@matthewjumpsoffbuildings
Copy link
Contributor

matthewjumpsoffbuildings commented Nov 24, 2023

When at scale, Spanner docs often suggest using composite keys for the primary key, for example using a ShardId combined with the other columns, something like PRIMARY KEY (ShardId, Id)

Is there already a proper way to do this using this driver? And to handle things like many-to-many relationships with composite primary keys etc?

I see there is an existing library for composite keys in Eloquent in general, https://github.com/thiagoprz/eloquent-composite-key - is that compatible with this driver perhaps?

@taka-oyama
Copy link
Collaborator

Is there already a proper way to do this using this driver?

No, you will have to add the constraints manually.

@taka-oyama
Copy link
Collaborator

I see there is an existing library for composite keys in Eloquent in general, https://github.com/thiagoprz/eloquent-composite-key - is that compatible with this driver perhaps?

You can try, but I don't think that trait covers complex cases like relations.

@b141568
Copy link

b141568 commented Jan 16, 2024

We use this library too.
Laravel does not seem to support composite keys in certain circumstances. Laravel only identifies data with the primaryKey type "string".
But when using the library https://github.com/thiagoprz/eloquent-composite-key, it identifies string or array as primary key

For complex relationships we use
https://github.com/tylernathanreed/laravel-composite-relations

@taka-oyama
Copy link
Collaborator

But when using the library https://github.com/thiagoprz/eloquent-composite-key, it identifies string or array as primary key

That is not aligned with how laravel does things and may result in errors where string is expected to return from$model->getKey() so it may make upgrading to newer versions hard and painful.

For complex relationships we use https://github.com/tylernathanreed/laravel-composite-relations.

This overrides a lot of the logic from the base framework and that's quite risky when upgrading the underlying framework.

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

3 participants