UNPKG

@wearesage/schema

Version:

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

39 lines (34 loc) 763 B
import "reflect-metadata"; import { Entity, Id, Property, OneToOne, OneToMany } from "../.."; import { User } from "./User"; import { CartItem } from "./CartItem"; /** * A Cart belongs to exactly one User. * It holds many CartItems. */ @Entity() export class Cart { @Id() id: string; @Property({ default: () => new Date() }) createdAt: Date; /** * One-to-one with User (opposite side of the @OneToOne in User). */ @OneToOne({ target: () => User, inverse: "cart", name: "BELONGS_TO_USER", }) user: User; /** * A cart can have many CartItems. * The "inverse" property on CartItem is "cart". */ @OneToMany({ target: () => CartItem, inverse: "cart", name: "HAS_ITEM", }) items: CartItem[] = []; }