Repository pattern and relationships

Posted 11 months ago by xxRockOnxx

Searched the internet for this but even straight googling of this topic does not give anything related.

I would like the answers to be general programming answer rather than language or framework specific.

So in a repository pattern, how do you do relationships? Eager by default? Query if needed (kind of lazy load)? Have extra methods in repo?

Say StudentRepo which I think is the best example... would you

  • findStudentWithGuardian?
  • findStudentById and findGuardianByStudentId (on GuardianRepo)

First one seems dirty to me. What if you needed a nested relationship?

Eager load by default seems dangerous on some cases kind of 50/50 to be used a solid solution.

Those are the only solution solutions can think of. There might be some answers out there. How do you solve this?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.