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

Fix Incorrect Example for Defining Composite Primary Keys in Documentation #457

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

farhadham
Copy link

This pull request fixes the incorrect example in the Drizzle ORM documentation for defining composite primary keys using the primaryKey operator. The current example mistakenly uses an object with keys pk and pkWithCustomName to define composite primary keys. This syntax does not work as intended and may lead to confusion for developers.

Changes Made

  • Updated the composite primary key example to use the correct syntax:
  • Returned an array of primaryKey definitions directly instead of wrapping them inside an object.
  • Fixed incorrect component import in test files causing tests to fail

Before Change (Incorrect):

export const booksToAuthors = pgTable("books_to_authors", {
  authorId: integer("author_id"),
  bookId: integer("book_id"),
}, (table) => {
  return [{
    pk: primaryKey({ columns: [table.bookId, table.authorId] }),
    pkWithCustomName: primaryKey({ name: 'custom_name', columns: [table.bookId, table.authorId] }),
  }];
});

After Fix:

export const booksToAuthors = pgTable(
  "books_to_authors",
  {
    authorId: integer("author_id"),
    bookId: integer("book_id"),
  },
  (table) => {
    return [
      primaryKey({ columns: [table.bookId, table.authorId] }),
      primaryKey({ name: "custom_name", columns: [table.bookId, table.authorId] }),
    ];
  },
);

Closes #456

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

Successfully merging this pull request may close these issues.

Incorrect Example for Defining Composite Primary Keys
1 participant