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

Allow composite primary keys #82

Open
koredefashokun opened this issue May 30, 2020 · 1 comment
Open

Allow composite primary keys #82

koredefashokun opened this issue May 30, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@koredefashokun
Copy link

Recently, I created a table to handle a many-to-many relationship. In this case, I want the primary key to be a constrain on multiple columns, but the @model directive only supports a string as the value for the pk argument. I'm not sure what the API would look like, but it would definitely be useful to have the pk field support constrain primary keys.

Great work on this project. It has definitely made it easier for me to handle building my GraphQL server.

@danielrearden danielrearden added the enhancement New feature or request label May 30, 2020
@danielrearden danielrearden added this to the Possible features milestone May 30, 2020
@danielrearden danielrearden changed the title Allow constrain primary keys Allow composite primary keys May 30, 2020
@danielrearden
Copy link
Owner

Thanks for the feature request. This would go hand-in-hand with #53 , although offhand I'm not sure what the best approach would be to changing model methods like findById.

If the table in question doesn't need to be writable, you can utilize a view as a workaround. Either add the view to your database, or use an "inline" one:

@model(
  pk: "pk",
  cte: """
    SELECT
      pk1 || '_' || pk2 as pk,
      another_column,
      yet_another_column
    FROM your_table
  """
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants