Skip to content

Instantly share code, notes, and snippets.

@vinipachecov
Created May 30, 2020 22:17
Show Gist options
  • Save vinipachecov/8bcad0e802b8f190346471d811845eb2 to your computer and use it in GitHub Desktop.
Save vinipachecov/8bcad0e802b8f190346471d811845eb2 to your computer and use it in GitHub Desktop.
Posts file for React-Native typeorm setup
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToMany,
JoinTable,
ManyToOne,
} from 'typeorm/browser';
import { Category } from './category';
import { Author } from './author';
@Entity('post')
export class Post {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@Column('text')
text: string;
@ManyToMany((type) => Category, {
cascade: ['insert'],
})
@JoinTable()
categories: Category[];
@ManyToOne((type) => Author, (author) => author.posts, {
cascade: ['insert'],
})
author: Author;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment