2024/10/15 3

Methods

@Post('sample') async sample() { // 모델에 해당되는 객체 생성 - 저장은 안함 const user1 = this.userRepository.create({ email: 'test@codefactory.ai', }); // 저장 const user2 = await this.userRepository.save({ email: 'test@codefactory.ai', }); // preload // 입력된 값을 기반으로 데이터베이스에 있는 데이터를 불러오고 // 추가 입력된 값으로 데이터베이스에서 가져온 값들을 대체함 // 저장하지는 않음 // find + create const user3 = aw..

코딩/TypeORM 2024.10.15

Relationship

@Join 없는 곳 설정 안하면 단방향이 됨.- OneToOne// User@OneToOne(() => ProfileModel, (profile) => profile.user)profil: ProfileModel;// Profile@OneToOne(() => UserModel, (user) => user.profil)@JoinColumn() // JoinColumn 있는곳에 컬럼 생김user: UserModel;JoinColumn 있는곳에 컬럼 생김https://typeorm.io/one-to-one-relations  - OneToMany, ManyToOne// User@OneToMany(() => PostModel, (post) => post.author)posts: PostModel[];// Pos..

코딩/TypeORM 2024.10.15
728x90