So am working on Spring Boot project that help teachers group students , schedule sessions…
and i have this two classes user and group the problem is i don’t know if its better to make it bidirectional (like it is now) or to make it unidirectional by removing groups ref inside of the user because i thought that if i am going to find all groups that belongs to user x in his groups list its easier than finding all group that user x is part of from all the groups and same goes the other way.
this is my code right now which am not sure if its the best design i tried using chatgpt and copilot but they didn’t help me much.
User :
@Data
@Document(collection = "users")
@Builder
public class User implements UserDetails {
@Id
private String id;
@NotNull
@Indexed(unique = true)
@Email
private String email;
@NotNull
private String password;
@NotNull
private String name;
@NotNull
private String lastname;
private String image;
private List<String> groups;
private Role role;
@NotNull
private Boolean verified;
@NotNull
private Boolean ban;
}
Group :
@Data
@Document(collection = "groups")
@Builder
public class Group {
@Id
private String id;
private String name;
private String teacher;
private List<String> students;
}