I'm trying to create a self-relationship/subcategory using Adonisjs, but it returns the result []/null
. is there any solution?
models
@column()
public categoryId: string
@hasMany(() => Category)
public subCategory: HasMany<typeof Category>
controllers
const page = request.qs('page', 1)
const limit = request.qs('limit', 10)
const categories = await Category.query()
.whereNull('category_id')
.preload('subCategory')
.paginate(page, limit)
migrations
table.bigInteger('category_id').unsigned().references('categories.id').onDelete('cascade')