title: How do you implement one to many relationships in Clean Architecture
body: <p>I'm having problems using Clean Architecture. For those of you who have read Fernando Cejas' blog post
  <a href="http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/" rel="noreferrer">http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/</a>, my question is based on it, and his code.</p>
  
  <p>His example project has only one Domain Object a User. And everything is clear with POJOs. Where I am having a problem is, let's say that the user has books. A one to many relationship. How would you deal with this in Clean Architecture?</p>
  
  <p>Just like him I have a few layers, so 3 classes per Domain Object (User, UserModel, UserEntity) and a repository per Domain Object (UserDataRepository).
  Our new example would also have Book, BookModel, BookEntity and BookDataRepository.</p>
  
  <p>I also have use case classes with CRUD variations.</p>
  
  <p>The problem for me is at the UI/Presenter level. At this point in the program I have a UserModel object AND a list of BookModels. I do not have userModel.getBooks().  I do not have userModel.save() (which would save all the book changes too).</p>
  
  <p>To accentuate the problem, to make this analogy look even more like my actual use case, I also have the list of all the pages in the books! :)  So when I save the User, I want to save to books, and all the pages for every book that might have been modified.</p>
  
  <p>How would I go about this? </p>
  
  <p>Second BONUS question : In my real world problem, I have classes that derive from a base class. To use the above analogy:  LeftPage and RightPage would derive from PageBase.  A Book has a list.  However LeftPage and RightPage both have their separate repositories, separate use cases, etc.  (But this doesn't work)    How do I save a list ??  Do I have to make a separate use case SavePages which would have a :</p>
  
  <p>if (pages.elementAt(i) instanceof LeftPage) {
      SaveLeftPage saveLeft = new.....
  }
  else {
      SaveRightPage saveRight = new.....
  }</p>
  
  <p>I don't think that I can use Polymorphism because in all the documentation that I have seen, the Models don't know of the use cases.</p>
  
  <p>I hope that you can help, thank you very much for your time :)</p>
  
  <p>-MIke</p>