분류 전체보기

    @RelationId, 특정 필드에 대한 외래 키 값만 가져오기

    @RelationId, 특정 필드에 대한 외래 키 값만 가져오기

    @RelationId이 데코레이터는 엔티티의 관계를 사용하여 특정 필드에 대한 외래 키 값만을 직접 가져올 수 있게 해준다.관계를 전체 로드하지 않고도 필요한 정보만 가져올 수 있다.  import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";@Entity()export class Profile { @PrimaryGeneratedColumn() id: number; @Column() gender: string; @Column() photo: string;}  import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn, RelationId } from..

    Column 타입 JSON으로 지정, @Column({ type: "json" })

    Column 타입 JSON으로 지정, @Column({ type: "json" })

    @Column({ type: "json" })TypeORM에서 JSON 형식의 데이터를 데이터베이스 열(column)에 저장할 때 사용하는 데코레이터이다.JSON 데이터는 복잡한 구조를 가지며, 다양한 유형의 데이터를 포함할 수 있다.type: "json"을 지정하면, 해당 열에 JSON 형식의 데이터를 저장하고 쿼리할 수 있다.구조화된 데이터를 저장하거나, 특정 형태를 가진 데이터를 저장해야 할 때 json type을 사용한다.복잡한 데이터일 경우 Entity에 넣지 않고 json 타입으로 저장하기도 한다.json은 MySQL, PostgreSQL에서 지원하는 데이터 타입이다.  import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";@Ent..

    Relations 정리 One-to-One, @JoinColumn()

    Relations 정리 One-to-One, @JoinColumn()

    @One-to-Oneimport { Entity, PrimaryGeneratedColumn, Column } from "typeorm"@Entity()export class Profile { @PrimaryGeneratedColumn() id: number @Column() gender: string @Column() photo: string}import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn,} from "typeorm"import { Profile } from "./Profile"@Entity()export class User { @PrimaryGeneratedCo..

    Relations 정리 OneToMany, ManyToOne

    Relations 정리 OneToMany, ManyToOne

    @ManyToOneimport { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"import { User } from "./User"@Entity()export class Photo { @PrimaryGeneratedColumn() id: number @Column() url: string @ManyToOne(() => User, (user) => user.photos)}여러 개의 자식 엔티티가 하나의 부모 엔티티와 연결될 때 사용ManyToOne 관계에만 집중하고 싶다면 관련 enity에 OneToMany 없이 정의할 수 있다.  @OneToManyimport { Entity, PrimaryGenerate..