-
-
Save ericwooley/38a11d3e40a8464c116701f880ee70d0 to your computer and use it in GitHub Desktop.
List Items with relations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export * from './lib/entity/TodoItem'; | |
export * from './lib/entity/List'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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