-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Omitting @OneToMany decorator is valid? #2059
Comments
yes it is valid, you can omit it if you don't need it. |
Could I face any problems by ommiting these? |
No |
Then this should be a bug, right? If I can just omit it to solve the error? Or on the other hand: Could I solve the error without omitting it? |
circular reference issue isn't a typeorm issue. Try to redesign your classes to avoid this issue. |
@pleerock, how should this be designed to avoid this error? Can you do something like
and it still is valid? |
I can help if you provide a minimal reproduction repo |
@pleerock from the README:
This seems to state that circular references are not only encouraged, they're required. |
@errorx666 correct, because bi-directional relation is circular by nature. |
So this feature is just not supported with ECMAScript modules/webpack, as they don't allow this? |
ECMAScript modules does not cover it right? What about webpack, I don't know, it might throw warnings, but it will still work. And it is working in node if we talk about node. |
I get the Foo is not defined errors with node using webpack awesome-typescript-loader (es2017 target) + babel-loader. |
you use webpack on the backend? |
Correct. |
maybe some specifics of tools you are using. Try to provide inline require, e.g. |
That had the same problem. Changing my |
How can this bug be closed? There is no resolution provided and it is still hapening |
If you have similar problem ask on slack or create new issue, but in both cases provide minimal reproduction data - otherwise we won't have enough information to be able to help. |
The problem is basically with ESM, because circular references give null values. Using commonjs instead of ESM is the workaround. I still think typeorm should support ESM. |
I think there is no way to resolve current circular references issue that happens in some particular cases using decorators. Solution might be to use |
For future reference and googlers: #4190 You can now pass strings to the @OneToMany('entity_name', 'attribute_name') |
It doesn't actually.. I get null values |
|
This fixes my OneToMany/ManyToOne relations, but for some reason does not fix the circular dep issue with OneToOne. Any ideas? |
Issue type:
[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[x]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
TypeORM version:
[x]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
I got these Entities. The Meter Entity has two foreign keys: UserId and HomeId. It looks like I am creating a circular dependency as I get this error (Gas, Water and Electricity are just empty Entities which inherit from Meter):
export class Gas extends Meter { }
TypeError: Class extends value undefined is not a constructor or null
However when I omit the @onetomany decorator I don´t get the error and everything works fine. Is that a valid behaviour?
The text was updated successfully, but these errors were encountered: