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

Can't use an ENUM as a foreign key in "hasMany" association #14724

Open
doneumark opened this issue Jul 7, 2022 · 1 comment
Open

Can't use an ENUM as a foreign key in "hasMany" association #14724

doneumark opened this issue Jul 7, 2022 · 1 comment
Labels
type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.

Comments

@doneumark
Copy link

doneumark commented Jul 7, 2022

Hi,
Having two models:

First {
    type: DataTypes.ENUM('A', 'B', 'C'),
}
B {
    type: DataTypes.ENUM('A', 'B', 'C'),
}

While having a hasMany association between them:

A.hasMany(B, {
    as: 'bs',
    foreignKey: 'type',
    sourceKey: 'type',
});

Making it impossible to query with joining the tables, as I get: operator does not exist: "enum_a_type" = "enum_b_type"
Which makes sense, as a different enum type is created for each table, making them unable for a comparison.

Should I add something to the query? or should you find a way to have single enum type to be used is serval tables?

@doneumark doneumark added the type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference. label Jul 7, 2022
@ephys
Copy link
Member

ephys commented Jul 8, 2022

Such a feature is dependent on #2577 being implemented in postgres

You can work around this by creating your enum manually first, then using the name of the enum as the type

First {
  type: `my_enum_name`,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.
Projects
None yet
Development

No branches or pull requests

2 participants