-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Enum not resolved if it is from an external file #6540
Comments
I've added a test, but I could not reproduce the issue. Can you please add a reproduction repo showing this erroneous behavior? |
@AlexMesser here is an example: https://stackblitz.com/edit/typeorm-not-working-enum. However, you can't run it online, you have to download it, there isn't a database connected (first time using stackblitz). The incriminated file is |
I can replicate this too. Enum ActionStatus is causing issues. It works in Entity 1 but not if I import it and try and use it in Entity 2. Entity 1:
Entity 2:
Fails with
If I redefine the enum in entity 2, it works:
|
This behaviour happens here as well. I found that the This bug affects also |
Okay, I checked @jeznag and know what is the issue. The issue is in JavaScript runtime behavior. You are circular referencing files, and To ensure I'm right, just console.log() your enum inside This issue can't be resolved, because it's related to JavaScript runtime behavior. Solution: extract enum to a separate file with only enum(s) definitions. |
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[x]
mysql
/mariadb
[ ]
oracle
[ ]
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:
I am using nestjs, I have defined an enum in an entity and used there. I needed to use it also in another entity, however, using an import typeorm seems to not resolve it.
In my file
order.entity.ts
I defineand in the issue entity
order-product.entity.ts
I write:The resulting query is
CREATE TABLE `order_product` (`id` int NOT NULL AUTO_INCREMENT, `status` enum NOT NULL, PRIMARY KEY (`id`))
producing an sql error as the enum is not defined.The error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL, PRIMARY KEY (`id`))' at line 1
Defining the enum also inside the orderProduct entity file the enum is resolved and the query is executed correctly.
The text was updated successfully, but these errors were encountered: