mikro-orm icon indicating copy to clipboard operation
mikro-orm copied to clipboard

NamingStrategy manyToMany relation name API

Open chiliman-oOo opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. There is no way to change only ManyToMany relation name's strategy in NamingStrategy.columnNameToProperty https://github.com/mikro-orm/mikro-orm/blob/623ee3a9768a88184c8b249250135b891261886a/packages/entity-generator/src/EntityGenerator.ts#L243

Describe the solution you'd like Make api NamingStrategy.manyToManyName(entityName: string, pivotEntityName:string, ...): string

chiliman-oOo avatar Jul 25 '24 13:07 chiliman-oOo

It's enough to add a parameter to that method, having something like manyToManyName sounds weird if we wouldn't have the other relation kind methods too.

B4nan avatar Jul 25 '24 13:07 B4nan

It would be far trickier to include 1:1 and M:1 relations into that same method, as the generator is very opinionated and changes its mind in a lot of places based on many factors 😅

Those other relations would need different kinds of extra information to be able to provide a good name. Notably, the names of existing un-skipped column properties (to avoid conflicts with them...).

A dedicated method for the manyToMany would bypass all of that. And other methods can be added for the other relation types based on their needs to make a determination. Besides... manyToMany generation happens after onInitialMetadata, which means this custom method doesn't need any extra information (unlike the other relations...). Whatever it needs, the naming strategy can be fed during onInitialMetadata.

boenrobot avatar Jul 25 '24 13:07 boenrobot

Hmm, ok, then I am not really sold on this being a good first issue :D The code in the entity generator is getting really complex, and it is indeed really intertwined.

B4nan avatar Jul 29 '24 07:07 B4nan