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

Resetting Sequence

Open whoisstan opened this issue 6 years ago • 1 comments

Hi, I have a factory that defines a property like this:

duration: Factory.sequence(function(n) { return n }),

I create multiple sets of objects

await factory.createManyAsync('object', 200 )
await factory.createManyAsync('object', 200,{ref:hardcoded_id} )

Now for the second set I like the duration sequence to start from the beginning again, how can I do that? I that possible?

Best, Stan

whoisstan avatar Jul 05 '18 16:07 whoisstan

Solved it this way, the name of specific sequence 'createdAtSequence' can be passed in via buildOptions.

... createdAt: factory.sequence(buildOptions.createdAtSequence||'createdAt', n=> { return moment().add(parseInt((n-1)/buildOptions.per_day||100),'days').toDate() } ) ...

whoisstan avatar Jul 05 '18 19:07 whoisstan