File

src/article/article.entity.ts

Index

Properties
Methods

Properties

author
author: UserEntity
Type : UserEntity
Decorators :
@ManyToOne(undefined, undefined)
body
body: string
Type : string
Decorators :
@Column({default: ''})
comments
comments: Comment[]
Type : Comment[]
Decorators :
@OneToMany(undefined, undefined, {eager: undefined})
@JoinColumn()
created
created: Date
Type : Date
Decorators :
@Column({type: 'timestamp', default: undefined})
description
description: string
Type : string
Decorators :
@Column({default: ''})
favoriteCount
favoriteCount: number
Type : number
Decorators :
@Column({default: 0})
id
id: number
Type : number
Decorators :
@PrimaryGeneratedColumn()
slug
slug: string
Type : string
Decorators :
@Column()
tagList
tagList: string[]
Type : string[]
Decorators :
@Column('simple-array')
title
title: string
Type : string
Decorators :
@Column()
updated
updated: Date
Type : Date
Decorators :
@Column({type: 'timestamp', default: undefined})

Methods

updateTimestamp
updateTimestamp()
Decorators :
@BeforeUpdate()
Returns : void
import { Entity, PrimaryGeneratedColumn, Column, OneToOne, ManyToOne, OneToMany, JoinColumn, AfterUpdate, BeforeUpdate } from 'typeorm';
import { UserEntity } from '../user/user.entity';
import { Comment } from './comment.entity';

@Entity('article')
export class ArticleEntity {

  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  slug: string;

  @Column()
  title: string;

  @Column({default: ''})
  description: string;

  @Column({default: ''})
  body: string;

  @Column({ type: 'timestamp', default: () => "CURRENT_TIMESTAMP"})
  created: Date;

  @Column({ type: 'timestamp', default: () => "CURRENT_TIMESTAMP"})
  updated: Date;

  @BeforeUpdate()
  updateTimestamp() {
    this.updated = new Date;
  }

  @Column('simple-array')
  tagList: string[];

  @ManyToOne(type => UserEntity, user => user.articles)
  author: UserEntity;

  @OneToMany(type => Comment, comment => comment.article, {eager: true})
  @JoinColumn()
  comments: Comment[];

  @Column({default: 0})
  favoriteCount: number;
}

result-matching ""

    No results matching ""