Veap provides four reusable polymorphic ORM traits that extend any @veap/database Model subclass through TypeScript class mixins and shared polymorphic database tables—without adding extra columns to your domain tables.
How Veap ORM traits work#
Each trait package exports:
- A class mixin function (
Translatable(Model),Taggable(Model),Categorizable(Model),Commentable(Model)) that attaches typed relation methods, query scopes, and lifecycle hooks (afterSave,beforeDelete) to your model. - Polymorphic Active Record models (
Translation,Tag,Category,Comment) backed by shared<morph>_typeand<morph>_idcolumns so multiple models (Article,Product,Course) share a single set of trait tables. - Reversible migrations exported from
<package>/migrationsthat you spread into your application'smigrations/index.tsarray.
ts
// lib/models/article.ts
import { Model } from "@veap/database";
import { Categorizable } from "@veap/categorizable";
import { Commentable } from "@veap/commentable";
import { Taggable } from "@veap/taggable";
import { Translatable } from "@veap/translatable";
export class Article extends Commentable(
Categorizable(Taggable(Translatable(Model))),
) {
static override table = "articles";
static translatable = ["title", "content"];
}Available ORM trait packages#
Explore each trait package in detail:
@veap/translatable— Multilingual model attributes stored in a polymorphictranslationstable with automatic proxy access and locale-scoped queries.@veap/taggable— Polymorphic, translatable tags (tagsandtaggablestables) withsyncTags,attachTags, andwhereTag/whereAnyTag/whereAllTagsquery scopes.@veap/categorizable— Hierarchical parent-child categories (categoriesandcategorizablestables) with tree queries and<CategoryTreeSelect />.@veap/commentable— Threaded polymorphic comments, nested replies, ratings, and moderation statuses (pending,approved,spam,rejected,trash).