typeorm-factory icon indicating copy to clipboard operation
typeorm-factory copied to clipboard

`Factory.attr(_, value)` support value function

Open ivawzh opened this issue 4 years ago • 3 comments

Hi.

I am trying to use Faker with Factory.attr. Currently, the second argument is limited to T[K] from attr<K extends keyof T>(name: K, value: T[K]).

Would you please make it support value: T[K] | () => T[K]?

ivawzh avatar Jul 30 '20 15:07 ivawzh

Hello @ivawzh, you can use the sequence method to do that:

.sequence('username', (_) => faker.internet.userName());

RodolfoSilva avatar Aug 19 '20 23:08 RodolfoSilva

Hi @RodolfoSilva, thanks for the workaround tips.

Meanwhile imho, it'd still be better to have an intuitive API that uses the right names for the right things. sequence is normally referred to a sequential number-embedded generator. value function is better reflecting a stateless attribute value generator.

ivawzh avatar Aug 20 '20 00:08 ivawzh

I agree, something like https://preview.adonisjs.com/guides/database/factories

RodolfoSilva avatar Aug 20 '20 10:08 RodolfoSilva