-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Naming errors in Entity Generator #5400
Comments
About 1, you can also use a custom naming strategy as a more "legit" workaround. Extend the underscore one, and override the getEntityName() method. This way, you'll ensure that any references to these tables are also updated properly. You can do that in the hooks too, sure, but it's more work for the hook. |
About 2... can you share the database's DDL? Not the full... just a reduced subset, including just the tables involved above. I was recently tackling weird edge cases like this, with the results so far being in #5359, but as I mention even there, there is one edge case that's not covered there, and inherently also in the current version... identifiers with dot in the name. I suspect you have something (table, column, index name, FK constraint name...) that has a dot in its identifier, and that ends up screwing the whole thing. Or perhaps this is a problem with cross schema FKs... hard to tell without a DDL. Oh, and btw... you could work around that via a custom naming strategy too... override columnNameToProperty(). |
@boenrobot About 1, I hadn't seen about Naming Strategy, it really is enough for the problem :) |
I've added a fix for the first problem in #5359, so that you wouldn't need to override getEntityName(). The same PR also already addressed having invalid characters as identifiers by quoting, meaning that your first example would become @ManyToOne({ entity: () => FrUsuario, ref: true, fieldName: "usr_codigo_app" })
'public.frUsuario'!: Ref<FrUsuario>;
@ManyToOne({ entity: () => SftSubProduto, ref: true, fieldName: "subpro_id_subtituto", nullable: true })
'public.sftSubProduto'?: Ref<SftSubProduto>;
@OneToOne({ entity: () => SftContatoWhatsOptIn, ref: true, mappedBy: "public.sftContato" })
'public.sftContatoInverse'?: Ref<SftContatoWhatsOptIn>; which is a valid class definition, where you can access the properties via f.e. (in the case of the first) Fixing the "true" problem of the schema name being at all present in the FK name will require more significant refactoring, which I already plan to tackle for the sake of supporting "." in identifiers. As already mentioned, you can workaround this in the meantime by overring columnNameToProperty() in the naming strategy. The problem is that when generating a |
Describe the bug
There are two minor bugs about naming in the Entity Generator.
1. Class names that not follows Pascal Case
In entities with more than one underscore between words, pascal case is not applied correctly.
As a temporary workaround, I'm using lodash as follows:
2. When using
scalarPropertiesForRelations: 'always',
some relations are not formatted correctlyIt appears to only happen with ManyToOne and OneToOne relationships. In this case, 'public' is the schema name.
Reproduction
What driver are you using?
@mikro-orm/postgresql
MikroORM version
6.1.12
Node.js version
v20.11.1, typescript 5.3.3
Operating system
Windows 11
Validations
The text was updated successfully, but these errors were encountered: