Last active
September 13, 2020 18:04
-
-
Save SergeyMell/ad35b4e5c220c517a246bb6e921faa60 to your computer and use it in GitHub Desktop.
TypeORM joined tables
This file contains hidden or 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 { BaseEntity, Column, Entity, OneToMany, PrimaryColumn } from 'typeorm'; | |
import { UseAsTitle } from 'admin-bro-typeorm'; | |
import { Post } from '../../posts/entities/post.entity'; | |
@Entity('users') | |
export class User extends BaseEntity { | |
@PrimaryColumn({ | |
name: 'pk_user', | |
generated: 'increment', | |
}) | |
pkUser: number; | |
@Column({ name: 'first_name' }) | |
firstName: string; | |
@Column({ name: 'last_name' }) | |
lastName: string; | |
@Column() | |
link: string; | |
@OneToMany(_type => Post, post => post.user) | |
posts: Post[]; | |
@UseAsTitle() | |
fullName(): string { | |
return `${this.firstName} ${this.lastName}`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment