UNPKG

@wearesage/schema

Version:

A flexible schema definition and validation system for TypeScript with multi-database support

30 lines (24 loc) 583 B
import "reflect-metadata"; import { Entity, Id, Property, ManyToMany } from "../.."; import { Product } from "./Product"; /** * A Category can have many products, * and a product can belong to many categories (Many-to-Many). */ @Entity() export class Category { @Id() id: string; @Property({ required: true, unique: true }) name: string; @Property() description: string; @Property({ default: () => new Date() }) createdAt: Date; @ManyToMany({ target: () => Product, inverse: "categories", name: "HAS_PRODUCT", }) products: Product[] = []; }