Skip to content

Commit

Permalink
refactor: Add @ManyToOne mapping (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahyun0326 committed Apr 19, 2024
1 parent 47e01a1 commit f28977e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/beotkkot/qtudy/domain/comments/Comments.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.beotkkot.qtudy.domain.comments;

import com.beotkkot.qtudy.domain.posts.Posts;
import com.beotkkot.qtudy.domain.user.Users;
import jakarta.persistence.*;
import lombok.*;

Expand All @@ -13,11 +15,13 @@ public class Comments {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long commentId;

@Column(nullable = false)
private Long postId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private Posts post;

@Column(nullable = false)
private Long userUid;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private Users user;

@Column(columnDefinition = "TEXT")
private String content;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/beotkkot/qtudy/domain/quiz/Review.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.beotkkot.qtudy.domain.quiz;

import com.beotkkot.qtudy.domain.user.Users;
import jakarta.persistence.*;
import lombok.*;

Expand All @@ -13,8 +14,9 @@ public class Review {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private Long userId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private Users user;

@Column(nullable = false)
private Long postId;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/beotkkot/qtudy/domain/tags/Tags.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.beotkkot.qtudy.domain.tags;

import com.beotkkot.qtudy.domain.category.Category;
import jakarta.persistence.*;
import lombok.*;

Expand All @@ -18,7 +19,9 @@ public class Tags {

private int count; // 태그 언급 횟수

private Long categoryId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
private Category category;

public void increaseTagCount() {
this.count++;
Expand Down

0 comments on commit f28977e

Please sign in to comment.