import { BaseModel, column, manyToMany } from "@adonisjs/lucid/orm" import type { ManyToMany } from "@adonisjs/lucid/types/relations" export default class Page extends BaseModel { protected tableName = "pages" /** * Page id is unique for each page on Wikipedia, can be used to link to the page. * @example `https://${locale}.wikipedia.org/?curid=${pageId}` */ @column({ columnName: "id", serializeAs: "id", isPrimary: true }) declare id: number /** * Title of the Wikipedia page. */ @column({ columnName: "title", serializeAs: "title", }) declare title: string @manyToMany( () => { return Page }, { pivotTable: "internal_links", localKey: "id", relatedKey: "id", pivotForeignKey: "from_page_id", pivotRelatedForeignKey: "to_page_id", serializeAs: "internalLinks", }, ) declare internalLinks: ManyToMany } export type PageRaw = Pick export type PageWithInternalLinksRaw = PageRaw & { internalLinks: PageRaw[] }