简体   繁体   中英

Can we have models who depends on each other?

class Parent {
    long id;
    List<Child> children;   
}

class Child {
    long id;
    Parent parent;
}

GET /parents/1, here have to show children of Parent 1

GET /children/101 here have to show Parent of Child 101

I actually didnt like above circular dependency design, but I am not understanding how to fix above scenario. Need some help to fix above design issue.

And also iam not sure whether can we have DTOs who depends on each other? Is this correct design?

Yes. You can have models that depend on each other. This is widely used in hibernate. Your example is like one to many mapping.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM