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 Primary Key Support #1664

Open
mrhwick opened this issue Oct 12, 2017 · 4 comments
Open

Composite Primary Key Support #1664

mrhwick opened this issue Oct 12, 2017 · 4 comments

Comments

@mrhwick
Copy link
Member

mrhwick commented Oct 12, 2017

Composite Primary Keys

Related Issues:

I searched for all issues that reference composite primary keys in some way. Most of these are directly issues resulting from our lack of composite key support. Some only indirectly involve composite keys.

Introduction

Composite or Compound primary keys are used when a single column value is not enough to define the unique ID of a record on some table. These are widely used, especially in the context of multi-tenant applications. There have been many calls for implementation of composite primary keys.

@bgerd
Copy link

bgerd commented Oct 7, 2019

Just discovered this while migrating an existing postgres schema to Bookshelf. Is there a best practice pattern / workaround for handling composite primary keys?

All I could find is that you have to override idAttribute with a getter returning null ... https://bookshelfjs.org/api.html#Model-instance-idAttribute

@pkantsedalov
Copy link

pkantsedalov commented Sep 25, 2020

@bgerd I am trying that on the latest versions of both bookshelf and knex and have the same problem: it tries to fetch data using null column. So, the solution doesn't seem to be workable in the latest versions.

By the way, this feature is a must. Without that bookshelf is dying: you can't upgrade your dependencies to the latest versions w/o composite PKs

@jayarjo
Copy link

jayarjo commented Feb 9, 2021

If it doesn't support composite keys, how on earth does it claim to support Many-to-Many?

@keyvanestermann
Copy link

If it doesn't support composite keys, how on earth does it claim to support Many-to-Many?

Bookshelf assumes (wrongly) that a pivot table HAS to have an "id attribute", when most pivot tables are composed with the primary keys of the individual entities in your many-to-many relation.

I am baffled this is still an issue, since I have been reading about it for 3 years.

If anyone is reading this : my solution to this problem was to create an "ID" field on my table, set on auto_increment with a UNIQUE index.
It serves absolutely no purpose, but Bookshelf is happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Version 4.0.0
  
To do
Development

No branches or pull requests

5 participants