Skip to content

Instantly share code, notes, and snippets.

@albizan
Created April 15, 2019 16:07
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 albizan/bc1c9e6050544c07e98e47601b8f3e6b to your computer and use it in GitHub Desktop.
Save albizan/bc1c9e6050544c07e98e47601b8f3e6b to your computer and use it in GitHub Desktop.
Relation
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
import { User } from './user.entity';
@Entity()
export class Role {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({
unique: true,
})
name: string;
}
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
ManyToMany,
JoinTable,
} from 'typeorm';
import { Role } from './role.entity';
@Entity()
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
name: string;
@Column({
unique: true,
})
email: string;
@Column()
password: string;
@CreateDateColumn()
insertedAt: Date;
@UpdateDateColumn()
updatedAt: Date;
@ManyToMany(type => Role)
@JoinTable()
roles: Role[];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment