inflearn logo
강의

Course

Instructor

[Code Camp] Highly concentrated backend course created at boot camp

10-01 Entity Implementation

ManyToMany 테이블이 자동으로 만들어지지 않습니다..

Resolved

439

karmesin924

4 asked

0

 

import { ProductCategory } from 'src/apis/productsCategories/entites/productCategory.entity';
import { ProductSaleslocation } from 'src/apis/productsSaleslocations/entities/productSaleslocation.entity';
import { ProductTag } from 'src/apis/productsTags/entities/productTag.entity';
import { User } from 'src/apis/users/entities/user.entity';
import {
  Column,
  Entity,
  JoinColumn,
  JoinTable,
  ManyToMany,
  ManyToOne,
  OneToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';

@Entity()
export class Product {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  name: string;

  @Column()
  description: string;

  @Column()
  price: number;

  @Column({ default: false })
  isSoldout: boolean;

  @JoinColumn() // 1:1 연결에서는 두 테이블 중 중심을 정하는 JoinColumn을 달아주어야한다.
  @OneToOne(() => ProductSaleslocation) // 일대일 연결. 어떤 테이블이랑 연결될지 표기. ProductSaleslocation 테이블과 연결 할 것이다.
  productSaleslocation: ProductSaleslocation; // 그 때 사용되는 Column은 productSaleslocation이고 타입은 다음과 같다, FK

  @ManyToOne(() => ProductCategory) // many가 Product 한개인게 Category
  productCategory: ProductCategory; // FK

  @ManyToOne(() => User)
  user: User;

  @JoinTable() // ManyToMany는 둘 중 하나에 JoinTable 작성
  @ManyToMany(() => ProductTag, (productTags) => productTags.products) // 상대방 입장에서 나를 볼 때 products
  productTags: ProductTag[]; // 객체가 여러개이기 떄문에 객체 배열타입 사용
}

 

import { Product } from 'src/apis/products/entities/product.entity';
import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class ProductTag {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  name: string;

  @ManyToMany(() => Product, (products) => products.productTags)
  products: Product[];
}

ManyToMany 설정했는데.. product_product_tags_product_tag 테이블이 자동으로 생성이 안되네요. 코드 말고 건드려줘야 할 부분이 있나요?

javascript node.js docker rest-api nestjs

Answer 2

1

karmesin924

우왁..!! 바로 해결됐습니다. 감사합니다!!

0

nwd09074926

안녕하세요! karmesin924님!

올려주신 코드는 잘 작성해 주신 것 같아요!
데이터베이스 이름을 선택하여 마우스 오른쪽버튼을 눌러서 새로고침을 한 번 해보시겠어요?!

아무데서나 새로고침하시면 안되시구, 데이터베이스명을 선택하여 새로고침을 해보세요!

그래프 ql 문서 사용할때 느낌표 남는거 어떻게 없애나요?

0

80

2

강의 전체 소스 코드를 받고싶습니다.

0

74

2

fontawesome 사용 문의

0

75

2

소스 코드 부탁드립니다~

0

84

2

깃 레포지터리 소스

0

78

2

커리큘럼12.css 정렬 에 나오는 과제 정답알고싶어요

0

71

2

10-01 Entity TypeOrmModule.forRoot 에 entities

0

83

3

강의 버전관련 문의입니다

0

101

2

Ubuntu 설치 관련

0

59

1

schema.gql 질문 드립니다.

0

49

1

서버 재실행시 Many to Many

0

100

3

input 관련 문의

0

89

2

Rest API 보다는 graphql이 주된 내용인데

0

130

2

강의 전체 소스코드 받을수있을까요?

0

153

1

도커볼륨 마운트 관련

0

125

2

findOne 타입스크립트오류

0

107

1

http => htrtps 호출 인증서 신뢰 오류

0

347

1

self-signed certificate in certificate chain 에러 발생

0

408

1

mongoose 설치 오류

0

140

1

특정 API, 특정 IP 허용 (단일경로에 CORS 활성화)

0

279

2

08-06

0

174

3

구조랑 패턴 관련해서 질문

0

121

2

mydocker

0

125

2

coolsms statuscode 2000 인데 전송안돼는 경우 확인.

0

153

1