Skip to content
Discussion options

You must be logged in to vote

I managed to solve the problem.

The model will look like this:

/* eslint-disable no-use-before-define */

import { DateTime } from 'luxon'
import {
  BaseModel,
  BelongsTo,
  beforeCreate,
  belongsTo,
  column,
  hasMany,
  HasMany,
} from '@ioc:Adonis/Lucid/Orm'
import { v4 as uuid } from 'uuid'

import Image from './Image'

export default class Category extends BaseModel {
  public static selfAssignPrimaryKey = true

  @beforeCreate()
  public static async createID(model: Category) {
    if (!model.id) {
      model.id = uuid()
    }
  }

  @column({ isPrimary: true })
  public id: string

  @column()
  public name: string

  @column()
  public parentId: string | null

  @column()
  p…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ivanvinicius
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant