-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Custom types on arrays in posgres generates the wrong name when using underscores in columns #13204
Copy link
Copy link
Closed
Labels
Great SSCCEThis issue has a great SSCCE/MCVE/reprex posted and therefore deserves extra attention! :)This issue has a great SSCCE/MCVE/reprex posted and therefore deserves extra attention! :)dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).status: understoodFor issues. Applied when the issue is understood / reproducible.For issues. Applied when the issue is understood / reproducible.type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Metadata
Metadata
Assignees
Labels
Great SSCCEThis issue has a great SSCCE/MCVE/reprex posted and therefore deserves extra attention! :)This issue has a great SSCCE/MCVE/reprex posted and therefore deserves extra attention! :)dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).status: understoodFor issues. Applied when the issue is understood / reproducible.For issues. Applied when the issue is understood / reproducible.type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Issue Description
When using underscored column names in pg enum array types, bulkUpdate queries fails (Actually this will happen for any field uses the "field" property to rename the column, as the data-type file in the postgres dialect is not using the correct "overwritten" propery)
What are you doing?
Here is the link to the SSCCE for this issue: sequelize/sequelize-sscce#158
What do you expect to happen?
I want that when using a model with underscored columns on the table in a postgres database, custom types in array are casted to the proper type when doing queries (in particular bulkCreate)
What is actually happening?
For a simple model like:
when executing the bulkCreate I'm expecting that the data is inserted, but instead fails
the error output is clear
enum_book_details_originalCategoriesis not the proper type in the database, it should beenum_book_details_original_categoriesrespecting the underscoring.Additional context
Environment
Issue Template Checklist
How does this problem relate to dialects?
Would you be willing to resolve this issue by submitting a Pull Request?
Dev notes
I locally patched my code with a simple sed command:
sed -i 's/options\.field\.fieldName/options\.field\.field/g' ./node_modules/sequelize/lib/dialects/postgres/data-types.jsAnd from what I followed in the code is just a change on line 483 at
lib/dialects/postgres/data-types.jsinstead ofUtils.generateEnumName(options.field.Model.getTableName(), options.field.fieldName),the code should readUtils.generateEnumName(options.field.Model.getTableName(), options.field.field),(I debuged it to confirm and the sed patch works locally).So the change is realively easy, my only concern is extra testing that may be needed.