Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] DELETE /v1/articles/{id} 删除文章 数据库级联更新问题 #84

Closed
Nick-bit233 opened this issue Sep 8, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Nick-bit233
Copy link
Collaborator

Nick-bit233 commented Sep 8, 2021

问题1:ArticleServiceImpl.java 102行,应修改为:

if (!Objects.equals(authenticateUser.getId(), article.getAuthor().getId())) {
        throw new ForbiddenException("无权限删除该文章");
      }

image
注意:非java原生类型,请勿使用.equals函数进行等值判断
————————————————
问题2:当用户删除已有历史记录的文章时,由于history表中的含有其外键,SQL不允许父级删除。
请尝试修改为级联删除,或取消外键级联关系
image

错误详情:
java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (frogsoft_cms_db.history, CONSTRAINT FK2vowuipf9ugvhyk8nwigfu6si FOREIGN KEY (article_id) REFERENCES article (id))

@Nick-bit233 Nick-bit233 added the bug Something isn't working label Sep 8, 2021
@Nick-bit233 Nick-bit233 added this to To be assigned in Frogsoft CMS - backend via automation Sep 8, 2021
@Nick-bit233
Copy link
Collaborator Author

更新:删除用户也有同样的问题,用户创建的文章不能同步删除

Frogsoft CMS - backend automation moved this from To be assigned to To be deployed Sep 8, 2021
@lin594 lin594 moved this from To be deployed to Done in Frogsoft CMS - backend Sep 8, 2021
@lin594 lin594 reopened this Sep 8, 2021
@Nick-bit233
Copy link
Collaborator Author

  // fix:级联删除问题
  @OneToMany(cascade = CascadeType.ALL)
  @JoinColumn(name = "author")
  @OnDelete(action = OnDeleteAction.CASCADE)
  private Set<Article> articles;

以上是对User-Article一对多对多的外键添加方法,
理论上,每一个多对多,都要添加如上外键
结果有待后期测试

Frogsoft CMS - backend automation moved this from Done to To be deployed Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

3 participants