Closed miltonhowe closed 6 years ago
As for the removing of Id
sufix: I was thinking for some time of more generic solution. I'm planing to implement something similar to typeorm custom naming strategy. Then removing Id
sufix from relation names could be default behavior, but users would have the ability to change it if it doesn't suits theirs case.
Implemented in typeorm-model-generator@0.2.17
@Kononnable why this generator by default removes Id suffix?
Most of the time columns with this sufix are used only to relate two entities together. If you see a property(in typescript class) named categoryId
you expect it type to be number
, not Category
. Default naming strategy remove this sufix because of such cases.
Just take a look at sample2-one-to-one
in /test/integration/examples/
if it's not clear.
In our cases we often using user_id columns in selects. Using join to users table just for retreive id fields is stupid. Imho.
I'm think you're looking for @RelationId
decorator.
As for joining tables just to get Id - most(not sure if every) of modern db drivers should generate query plan which won't touch related table.
When the entity has a foreign key, the generator creates a property for the foreign table as an entity, and then leaves out the id field which keyed to the foreign entity. There should be an option to include both the foreign entity and the key from the original table. It would be nice as well if it could intelligently look for the
Id
suffix and remove and include it correctly.For example:
The
Id
gets chopped off for the Entity and included for the Id (here a string, sometimes an INT or other)