Repository pattern and relationships

Posted 7 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.