Weird seeder issue: ReferenceError: user is not defined

I have table called tags

Model

const Model = use('Model')
const uuidv4 = require("uuid/v4");
const Helper = user('App/Helpers/CustomHelper')


class Tag extends Model {

    static get incrementing() {
        return false
    }

    static boot() {
        super.boot()

        this.addHook('beforeSave', async (userInstance) => {
            if (!userInstance.dirty.id && !userInstance.id) {
                userInstance.id = uuidv4()
            }

            userInstance.slug = Helper.convertToSlug(userInstance.name)
        })
    }

    posts() {
        return this.belongsToMany('App/Models/Post').pivotTable('post_tag')
    }
}

module.exports = Tag

Seeder

const Tag = use('App/Models/Tag')

class TagSeeder {
  async run() {
    await Tag.create({ name: 'shit' })
    await Tag.create({ name: 'war' })
    await Tag.create({ name: 'code' })
    await Tag.create({ name: 'nano' })
    await Tag.create({ name: 'joker' })

  }
}

module.exports = TagSeeder

I am facing following error. There is no such things user in this file. I tried deleting all files and just tried with this file only still same error

2 Likes

Can you share migration with us?

Edit: All migrations related to this, Users, Pivot Table and Tag.

1 Like
const Helper = use('App/Helpers/CustomHelper')

It was my mistake. It was typo in ‘use’. Silly mistake. Hoping for typescript can help avoid such type of mistake in adonis 5. :smile:

1 Like