Skip to content

Commit

Permalink
Merge pull request #89 from CAUSOLDOUTMEN/fix/88-fix-food-favoritefood
Browse files Browse the repository at this point in the history
fix: food와 favoritefood간 연동 (#88)
  • Loading branch information
synoti21 authored Nov 13, 2023
2 parents 737ee7e + 8719b09 commit 7a347ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class FavoriteFood {

private String name;

@OneToOne(fetch = FetchType.LAZY, orphanRemoval = false) // 즐찾음식이 삭제되어도 음식은 삭제되지 않음
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST}, orphanRemoval = false) // 즐찾음식이 삭제되어도 음식은 삭제되지 않음
@JoinColumn(name = "food_id")
private Food food;

Expand All @@ -43,6 +43,7 @@ public static FavoriteFood createFavoriteFood(String name, User user, Food food,
favoriteFood.food = food;
favoriteFood.user = user;
favoriteFood.baseNutrition = baseNutrition;
food.setFavoriteFood(favoriteFood);
return favoriteFood;
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/diareat/diareat/food/domain/Food.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Food {
@JoinColumn(name = "user_id")
private User user;

@OneToOne(fetch = FetchType.LAZY, orphanRemoval = false) // 음식이 삭제되어도 즐찾음식은 삭제되지 않음
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST}, orphanRemoval = false) // 음식이 삭제되어도 즐찾음식은 삭제되지 않음
@JoinColumn(name = "favorite_food_id")
private FavoriteFood favoriteFood;

Expand All @@ -45,6 +45,7 @@ public static Food createFood(String name, User user, BaseNutrition baseNutritio
food.date = LocalDate.of(year, month, day);
food.addedTime = LocalDateTime.now();
food.baseNutrition = baseNutrition;

return food;
}

Expand All @@ -61,4 +62,8 @@ public boolean isFavorite() {
public void setId(long id) {this.id = id;}

public void setDate(LocalDate date) {this.date = date;} //food test를 위한 date

public void setFavoriteFood(FavoriteFood favoriteFood){
this.favoriteFood = favoriteFood;
}
}

0 comments on commit 7a347ad

Please sign in to comment.