Skip to content

Instantly share code, notes, and snippets.

@SergeyMell
Last active September 13, 2020 18:04
Show Gist options
  • Save SergeyMell/ad35b4e5c220c517a246bb6e921faa60 to your computer and use it in GitHub Desktop.
Save SergeyMell/ad35b4e5c220c517a246bb6e921faa60 to your computer and use it in GitHub Desktop.
TypeORM joined tables
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