-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Array of enums column doesn't work at all #4350
Comments
Please, a Hot Fix would be appreciated. This bug is very annoying. |
I created a WIP fix. The only thing which prevents me to create a pr, is the requirement to create a test... Index: src/driver/postgres/PostgresQueryRunner.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/driver/postgres/PostgresQueryRunner.ts (date 1563718253000)
+++ src/driver/postgres/PostgresQueryRunner.ts (date 1563909453000)
@@ -2006,9 +2006,28 @@
}
const result = await this.query(`SELECT "udt_schema", "udt_name" ` +
`FROM "information_schema"."columns" WHERE "table_schema" = '${schema}' AND "table_name" = '${name}' AND "column_name"='${column.name}'`);
+
+ let udtName = result[0]["udt_name"];
+
+ // You can not modify the array type. You need to edit the enum itself.
+ if (column.isArray) {
+ // Find the information about the array type
+ const typeResult = await this.query(`select "typelem" from pg_type where "typname" = '${udtName}';`);
+
+ const typelem = typeResult[0]["typelem"];
+
+ // Get with the oid of the enum array type the enum type
+ const baseTypeNameResult = await this.query(`select "typname" from pg_type where oid = ${typelem}`);
+
+ const baseTypeName = baseTypeNameResult[0]["typname"];
+
+ // Replace the udtName with the enum type
+ udtName = baseTypeName;
+ }
+
return {
enumTypeSchema: result[0]["udt_schema"],
- enumTypeName: result[0]["udt_name"]
+ enumTypeName: udtName
};
}
|
encountered this bug too, need to drop the database because of this. |
Dropping the database works but not a good solution for production |
Not a solution! But Instead of dropping the whole database, you could drop the column used by the enum with a migration that looks something like this:
You will still need to manually populate the dropped column. |
@TheNoim just clean ur build or dist folder. |
Why? About what are you talking? My pull request is a much better solution for this issue. |
@TheNoim are u in progress of fix now? I also have this problem |
Yes, I did. But someone needs to merge it: #6126 |
+1 same issue |
Ok, this bugs me because I'm pretty sure I used an array of enums in a past project a few months ago and I didn't get this error. @Column('enum', {
array: true,
enum: Object.values(RolesEnum),
default: [RolesEnum.reader],
}) Instead of @Column('enum', {
array: true,
enum: RolesEnum,
default: [RolesEnum.reader],
}) Now I can't make it work either way! |
Finally🤩🤯🥳 |
Issue type:
[ ] question
[ x ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[ x ]
postgres
[ ]
cockroachdb
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[ x ]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
Hello!
I have a problem with creating a Column for my ReviewEntity. I want to insert some enums inside an Array. It's working with an enum with only 1 char (like in this example, I have no idea why) but not if I add a value in enum after creation or if I use words.
It's working on the first launch (creation), but If I run again (with sync enabled) I will get an error.
review.entity
review.enums
Full error:
The text was updated successfully, but these errors were encountered: