danibram / mocker-data-generator

A simplified way to generate masive mock data based on a schema, you can use the awesome fake/random data generators like (FakerJs, ChanceJs, CasualJs and RandExpJs)
https://danibram.github.io/mocker-data-generator/
MIT License
426 stars 45 forks source link

How does unique work? #99

Closed patran closed 4 years ago

patran commented 4 years ago

With the User's field trueFalse uniquess being true, I had expected there would be at most 2 users generated. I got 30 users. Perhaps I have misunderstood how unique works. Please share your insights. Thanks

var user = { id: { chance: 'guid' }, name: { faker: 'name.findName' }, email: { faker: 'internet.email' }, trueFalse: { faker: 'random.boolean', unique: true } }; var house = { id: { chance: 'guid' }, address: { faker: 'address.streetAddress' }, householder: { hasOne: 'users' }, mateIds: { hasMany: 'users', max: 2, min: 2, unique: true } };

mocker() .schema('users', user, 30) .schema('houses', house, 1)

danibram commented 4 years ago

unique as is described in the documentation, only works with the hasMany generator, so it has any effect on your trueFalse field, only works on the mateIds filed inside house, and it ensure to have different users inside mateIds field.