Skip to content
This repository was archived by the owner on Oct 26, 2025. It is now read-only.
This repository was archived by the owner on Oct 26, 2025. It is now read-only.

Add Foreign Key Support #54

Open
Open

Description

@kingmesal

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?

Activity

  1. Skye-31 commented on Oct 14, 2022

    @Skye-31
    Contributor

    Duplicate of #23?

  2. kingmesal commented on Oct 14, 2022

    @kingmesal
    ContributorAuthor

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

    Foreign keys are not required to provide join support.

  3. sunnhyn commented on Dec 30, 2022

    @sunnhyn

    It seems great. 👍

  4. chrisspiegl commented on Mar 20, 2023

    @chrisspiegl

    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.

  5. Skye-31 commented on Mar 20, 2023

    @Skye-31
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions