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

@ManyToOne和@OneToMany #14

Open
Lynne0 opened this issue Sep 11, 2019 · 1 comment
Open

@ManyToOne和@OneToMany #14

Lynne0 opened this issue Sep 11, 2019 · 1 comment

Comments

@Lynne0
Copy link

Lynne0 commented Sep 11, 2019

请问楼主,User和Article,一对多的关系,为什么只在多端(Artcile表)里面使用@ManyToOne设置user_id外键关联user表,没有在一端(User表)里面设置@OnToMany List<Article> article 这个呢,求解答,谢谢

@shimh-develop
Copy link
Owner

@Lynne0 一对多的时候,一般由多的一方维护关系,也就是Article,保存Article时会先Set上User,来维护关系,并且取Artcile的时候,通常需要展示相应的User;没在User设置@OnToMany是因为除了不需要User来维护关系外,User也几乎不需要级联查询Artcile,获取User的时候一般只是需要自身的基础信息,你也可以加上,可以但没必要。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants