Skip to content

Documentation mismatch? No type property on ForeignKeyOptions #13429

Closed

Description

@xaragen

Working on a project I ran into the documentation for customizing the Foreign Key.
The docs read:

// https://sequelize.org/master/manual/assocs.html
// For example, to use UUID as the foreign key data type instead of the default (INTEGER), you can simply do:

const { DataTypes } = require("Sequelize");

Foo.hasOne(Bar, {
  foreignKey: {
    // name: 'myFooId'
    type: DataTypes.UUID
  }
});
Bar.belongsTo(Foo);

Good enough, but when I went to work on it, it threw an error :

 Object literal may only specify known properties, and 'type' does not exist in type 'ForeignKeyOptions'

Looking at the files, it seems true. Is this correct behavior, missing type or incorrect documentation?

export interface ForeignKeyOptions extends ColumnOptions {

EDIT:

After working on this, looks like it does work but the option is not part of the ForeignKey Options as described in the docs.

Foo.belongsTo(Bar, {
    foreignKey: {
        name: 'myFooId',
    },
    as: 'bars',
    keyType: sequelize.DataTypes.STRING,
});

Activity

  1. added
    type: bug
    on Aug 10, 2021
  2. self-assigned this
    on Aug 10, 2021
  3. removed
    type: bug
    on Aug 10, 2021
  4. github-actions commented on Oct 27, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

  5. github-actions commented on Nov 4, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

  6. added
    good first issue
    docs
    and removed on Nov 4, 2021
  7. bera5186 commented on Feb 27, 2022

    @bera5186

    Hey @Keimeno !! I would like to work on this issue. Please guide me with next steps.

  8. ephys commented on Feb 27, 2022

    @ephys
    Member

    This would be a good point to start an investigation: https://github.com/sequelize/sequelize/blob/main/src/associations/base.d.ts#L37
    ForeignKeyOptions extends ColumnOptions, which doesn't include type
    The only option bag that accepts type is ModelAttributeColumnOptions

    The question is:

    • can type be moved from ModelAttributeColumnOptions to ColumnOptions (what other methods use ColumnOptions and do they accept type)
    • can foreign key extend ModelAttributeColumnOptions? Does it support all of these options
    • or do we need to create an intermediary type
  9. bera5186 commented on Feb 27, 2022

    @bera5186

    Hey @ephys ,

    ModelAttributeColumnOptions extends ColumnOptions , so all the properties of ColumnOptions should be accessible via extending ModelAttributeColumnOptions.

    Looks like extending ModelAttributeColumnOptions in ForeignKeyOptions would work, but I think creating intermediary type is a better option.

    Correct me if I am wrong. Waiting for your inputs on this !

  10. ephys commented on Apr 16, 2022

    @ephys
    Member

    #13429 fixes this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docsgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions