How to describe such a relationship in the object model?


#1

Capture

probably so?

parent() {
    return this.belongsTo('Category', 'parent_id', 'id')
  }

Thank you in advance


#2

Migration file

this.create('categories', (table) => {
              table.increments()
              table.integer('parent_id').unsigned()
              table.string('name').notNullable()
              table.text('description')
}

Model

parents() { 
     this.hasMany('App/Models/Category', 'id', 'parent_id')
}