You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While I'm trying to seed a database with so many entities related, I found a problem and want to known if it is designed to work like this or if it is a bug.
It fails. As I can see in src/entity-factory.ts (L91):
privateasyncmakeEnity(overrideParams: EntityProperty<Entity>={},isSeeding=false): Promise<Entity>{if(this.factory){letentity=awaitthis.resolveEntity(this.factory(Faker,this.context),isSeeding)if(this.mapFunction){entity=awaitthis.mapFunction(entity)}for(constkeyinoverrideParams){if(overrideParams.hasOwnProperty(key)){entity[key]=overrideParams[key]}}returnentity}thrownewError('Could not found entity')}
overrideParams is being checked AFTER persisting/creating entity. Is this the expected behaviour?
We can extrapolate this as if I override a param that is a factory with another previously created entity, the original value is still on DB. Imagine seeding the database with thousands of rows.
The text was updated successfully, but these errors were encountered:
I will try to update the message to the last commit
privateasyncmakeEntity(overrideParams: EntityProperty<Entity>={},isSeeding=false): Promise<Entity>{if(!this.factory){thrownewError('Could not found entity')}letentity=awaitthis.resolveEntity(this.factory(Faker,this.context),isSeeding)if(this.mapFunction){entity=awaitthis.mapFunction(entity)}for(constkeyinoverrideParams){if(overrideParams.hasOwnProperty(key)){entity[key]=overrideParams[key]}}returnentity}
resolveEntity is creating/making some other entities that is related to the main entity, like this example:
field2 depends on seeding, but could be possible to be persisted. field3 is being persisted EVERY single time. This could cause some problems because if I try to create an entity this way:
Two EntityThree are being created but only the second is related. This can cause problems with UNIQUE restrictions or GET requests that lists resources
While I'm trying to seed a database with so many entities related, I found a problem and want to known if it is designed to work like this or if it is a bug.
Imagine that I have something like this:
and imagine that I have a
UNIQUE
flag onuniqueNumber
on typeorm entity and generate only 10 possible values because it is something an iso-code.If I try to run something like this:
It fails. As I can see in
src/entity-factory.ts
(L91):overrideParams
is being checked AFTER persisting/creating entity. Is this the expected behaviour?We can extrapolate this as if I override a param that is a factory with another previously created entity, the original value is still on DB. Imagine seeding the database with thousands of rows.
The text was updated successfully, but these errors were encountered: