Skip to content

Instantly share code, notes, and snippets.

@ericwooley

ericwooley/List.ts Secret

Created Apr 2, 2021
Embed
What would you like to do?
List Items with relations
export * from './lib/entity/TodoItem';
export * from './lib/entity/List';
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { TodoItem } from './TodoItem';
@Entity()
export class List {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@OneToMany(() => TodoItem, (item) => item.list)
items: Promise<TodoItem[]>;
}
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm';
import { List } from './List';
@Entity()
export class TodoItem {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column({ default: false })
done: boolean;
@ManyToOne(() => List, (list) => list.items)
list: Promise<List>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment