Skip to content

Instantly share code, notes, and snippets.

@ericwooley
Created April 2, 2021 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericwooley/38a11d3e40a8464c116701f880ee70d0 to your computer and use it in GitHub Desktop.
Save ericwooley/38a11d3e40a8464c116701f880ee70d0 to your computer and use it in GitHub Desktop.
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