Skip to content

Instantly share code, notes, and snippets.

@seandearnaley
Created June 8, 2020 15:56
Show Gist options
  • Select an option

  • Save seandearnaley/2d9aa55878f024f4605951de886eaafb to your computer and use it in GitHub Desktop.

Select an option

Save seandearnaley/2d9aa55878f024f4605951de886eaafb to your computer and use it in GitHub Desktop.
BrainStrike Category Entity / Model
import {
Entity,
Tree,
Column,
PrimaryGeneratedColumn,
TreeChildren,
TreeParent,
ManyToMany,
JoinTable,
} from "typeorm";
import { Card } from "./Card";
@Entity()
@Tree("closure-table")
export class Category {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column()
name: string;
@TreeChildren()
children?: Category[];
@TreeParent()
parent: Category;
@Column({
type: "timestamp",
nullable: false,
default: () => "LOCALTIMESTAMP",
})
created: Date;
@Column({
type: "timestamp",
nullable: false,
default: () => "LOCALTIMESTAMP",
})
updated: Date;
@ManyToMany(() => Card, (card) => card.categories)
@JoinTable()
cards: Card[];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment