Adonis factory TypeError: Cannot read property 'name' of undefined

Viewed 1833

This may have been asked already but i the answers i found didn't work on me, so i hope someone help me :)

Lately i've been trying to seed my database but i'm stuck at one problem.. i kept getting this error: TypeError: Cannot read property 'name' of undefined

Digging deep, i kinda found the error but as i'm new to this world i couldn't fix it on my own..

My factory.js

const Factory = use('Factory')
Factory.blueprint('App/Models/User', async faker => {`
   return {`
        name: faker.first(),
        surname: faker.last(),
        email: faker.email({ domain: 'somedomain.br' }),
        password: 'secret'
    }
})

My ClientSeeder.js

class ClientSeeder {
  async run() {
    const role = await Role.findBy('slug', 'client')
    console.log(role);
    const clients = await Factory.model('App/Models/User').createMany(30)
    await Promise.all(clients.map(async client => {
      await clients.roles().attach([role.id])
    }))
[...]

Error that i get

TypeError: Cannot read property 'name' of undefined
    at Factory.model (/mnt/c/wamp64/www/ecommerce/node_modules/@adonisjs/lucid/src/Factory/index.js:97:39)
    at ClientSeeder.run (/mnt/c/wamp64/www/ecommerce/database/seeds/0002_ClientSeeder.js:24:35)
    at async SeedDatabase.handle (/mnt/c/wamp64/www/ecommerce/node_modules/@adonisjs/lucid/commands/Seed.js:135:11)
    at async /mnt/c/wamp64/www/ecommerce/node_modules/@adonisjs/ace/src/Command/index.js:565:26

That's the part where i say i dug: In node_modules/@adonisjs/lucid/src/Factory/index.js:97:39 right at 97:39

  model(name) {
    console.log(`Valor saindo: ${name}`);
    const blueprint = this.getBlueprint(name)
    console.log(`CHEGOU AQUI O BLUEPRINT ${blueprint}`);
    return new ModelFactory(blueprint.name, blueprint.callback)
  }
//console.log(name) returns 'App/Models/User'
//console.log(blueprint) returns undefined;

Now, at getBlueprint()

  getBlueprint(name) {
    console.log(`Nome retornado: ${name}`);
    let bp = this._blueprints.find((blueprint) => blueprint.name === name)
    console.log(`O BP DESSA PORRA É ${bp}`);
    return
  }

//console.log(name) returns 'App/Models/User'
//console.log(bp) returns 'undefined'

Does anyone here have any idea of what is happening?

Package version

"@adonisjs/ace": "^5.0.8",
"@adonisjs/auth": "^3.0.7",
"@adonisjs/bodyparser": "^2.0.5",
"@adonisjs/cors": "^1.0.7",
"@adonisjs/fold": "^4.0.9",
"@adonisjs/framework": "^5.0.9",
"@adonisjs/ignitor": "^2.0.8",
"@adonisjs/lucid": "^6.1.3",
"@adonisjs/mail": "^3.0.10",
"@adonisjs/validator": "^5.0.6",
"@adonisjs/websocket": "^1.0.12",
"adonis-acl": "^1.1.1",
"adonis-bumblebee": "^2.2.0",
"mysql": "^2.18.1"

Migrations/Users.js

class UserSchema extends Schema {
  up() {
    this.create('users', (table) => {
      table.increments()
      table.string('name', 80).notNullable()
      table.string('surname', 80).notNullable()
      table.string('email', 254).notNullable().unique()
      table.string('password', 60).notNullable()
      table.integer('image_id').unique().unsigned()
      table.timestamps()
    })
  }

  down() {
    this.drop('users')
  }
}

Node.js and npm version

Node: v14.1.0

npm: 6.14.7

0 Answers
Related