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

Add Foreign Key Support #54

Open
kingmesal opened this issue Oct 14, 2022 · 5 comments
Open

Add Foreign Key Support #54

kingmesal opened this issue Oct 14, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@kingmesal
Copy link
Contributor

Adding on to #53 ...

For foreign keys there are a number of options a foreign key may have, but from a definition standpoint adding the foreign key to the column definition make the most sense as each column may only reference a single foreign column.

What I propose is the following:

{
  username: {
    type: DataTypes.STRING,
    unique: "some-arbitrary-key",
  },
  session: {
    type: DataTypes.STRING,
    foreignKey: {
      table: "session-table", // example like Model.tableName
      column: "session-table-field-name", // example like Model.columnName
      onDelete?: {
          cascade?: boolean,
          restrict?: boolean,
          setNull?: boolean,
          setDefault?: boolean,
      },
      onUpdate?: {
          cascade?: boolean,
          restrict?: boolean,
          setNull?: boolean,
          setDefault?: boolean,
      },
    },
  },
}

I think this approach is fairly straight-forward and easy to follow.

Thoughts?

@kingmesal kingmesal added the enhancement New feature or request label Oct 14, 2022
@Skye-31
Copy link
Contributor

Skye-31 commented Oct 14, 2022

Duplicate of #23?

@kingmesal
Copy link
Contributor Author

Why would foreign key definitions be a duplicate of join syntax ?

Foreign keys are not required to provide join support.

@StationSoen
Copy link

It seems great. 👍

@chrisspiegl
Copy link

Are you planning to add support for the foreign keys and join syntax to build relationships with this ORM?

Would be awesome to fetch things more easily this way.

@Skye-31
Copy link
Contributor

Skye-31 commented Mar 20, 2023

Are you planning to add support for the foreign keys and join syntax to build relationships with this ORM?

Would be awesome to fetch things more easily this way.

@chrisspiegl

Pulls welcome 😃

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

4 participants