feathers-plus / generator-feathers-plus

A Yeoman generator to (re)generate a FeathersJS application supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
44 stars 30 forks source link

How to use faker.js arrayElement #281

Closed chrisk8er closed 4 years ago

chrisk8er commented 4 years ago

hi guys, I want to generate some random fakes data to my MySQL database based on arrays that I created. I don't know how feathers-plus works with fakers, please help guys. thanks

I know I can do this with chance.gender . but I want to know how to dealing with some random that already defined.

sorry for my bad English.

this is my code:

// Fields in the model.
  properties: {
    // !code: schema_properties
    id: { type: 'ID' },
    username: { minLength: 3, maxLength: 15, faker: 'internet.userName'},
    password: { chance: { hash: { length: 60 }} },
    fullname: { minLength: 2, maxLength: 60, faker: 'name.findName'},
    roles: { type: 'ID', faker: { fk: 'roles:random'} },
    sex: { minLength:  4, maxLength: 6,   faker: 'arrayElement(["male", "female"])' },
    birthPlace: { faker: 'address.city'},
    birthday: { faker: 'date.past'},
    // !end
  },
  ...

Expected behavior

  "users": [
    {
      ...
      "sex": "male",
      ...
    },

Actual behavior

  "users": [
    {
      ...
      "sex": "undefi",
      ...
    },
    ...

System configurationModule versions (especially the part that's not working):

0.8.10 Operating System: macOS

chrisk8er commented 4 years ago

I found the answer here.

chrisk8er commented 4 years ago

I found the answer here.