Circular import causing entity manager to use the wrong entity name #6929
Replies: 3 comments 1 reply
-
|
It is not the ORM altering your entity names, its your bundler. I recall swc or esbuild do this. You can disable that behavior most likely. |
Beta Was this translation helpful? Give feedback.
-
|
If you can't / don't want to change the settings of your bundler, another workaround is to put all entities in a "barrel" file (you know, like index.ts that re-exports other files) and only ever import from it in the rest of your application (never the entity files directly). This doesn't fix the class name minification that swc and esbuild are also capable of doing (and do by default...), but it does work to cut out the copied versions. And you can use the entity reference with the |
Beta Was this translation helpful? Give feedback.
-
|
Thanks a lot for both of your replies, I just want to understand the confusion and your replies helped me a lot and pointed me to the right direction! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am not sure if it is a bug or just an issue for bad coding practice but I wanted to ask and shared what I found
If you have two entities that are related to each other, let's say Box and Item
In Box, you might import roles to have OneToMany relation
then in Role, if you import User to have the reference, it will introduce a circular import, like this
In development mode, it works totally fine
When you are managing the element, you can either choose
box.itemList.add(newItem)ornewItem.parentBox = newBox, both will work perfectly fine. However, if you are running using the built files (I am using containerized version), you will face the error similar toMetadata for entity Box2 not foundeven when just usingem.find(Box, ....)The entity manager added "2" at the end of the entity for no reason. I suspect that since there are two references for Box, the manager just trace the last one and used that one as the entity name for searching.
My solution is to remove the parentBox in Item entity, just use
box.itemList.add(newItem)for binding the relation between Box and Item, that resolve the issue and works perfectly fine for both development and production.However, I would like to know if it is intended behaviour, is it just not recommended to do so, I am just lucky that development mode works? Since I think some might prefer setting parentBox to bind the relationship, sometimes that might be a clearer solution
Beta Was this translation helpful? Give feedback.
All reactions