Skip to content

Commit

Permalink
[#18] [#5] 연관관계로 인한 삭제 버그 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
mangdo committed Jul 14, 2021
1 parent e8fae0a commit 34522f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Reply extends Timestamped {
private String replyWriter;

// Fk 가지는곳을 ManyToOne
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "planId")
private Plan plan;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
*/
public interface ReplyRepository extends JpaRepository<Reply, Long> {
List<Reply> findAllByPlan(Plan plan);
void deleteAllByPlan(Plan plan);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public void deletePlan(Long id, DeleteRequestDto requestDto) {
if (!plan.getPlanPassword().equals(requestDto.getPassword())) {
throw new ApiRequestException("비밀번호가 틀렸습니다.");
}

// 해당 plan와 연결되어있는 reply 먼저 삭제
replyRepository.deleteAllByPlan(plan);
// plan 삭제
planRepository.deleteById(id);
}

Expand Down

0 comments on commit 34522f7

Please sign in to comment.