Files
pc_builder/app/models/component.ts
T
2026-06-28 10:41:51 +02:00

39 lines
901 B
TypeScript

import { DateTime } from 'luxon'
import { BaseModel, belongsTo, column } from '@adonisjs/lucid/orm'
import ComponentType from '#models/component_type'
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
export default class Component extends BaseModel {
@column({ isPrimary: true })
declare id: number
@column()
declare name: string
@column()
declare price: number
@column({ serializeAs: null })
declare typeId: number
@belongsTo(() => ComponentType, {
foreignKey: 'typeId',
})
declare type: BelongsTo<typeof ComponentType>
@column()
declare computerId: number | null
@column({ serializeAs: null })
declare userId: number
@column.date()
declare purchaseDate: DateTime
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
}