I'm currently working on refactoring a project to use the repository pattern, but I'm currently struggling with how related information should be retrieved.
Let's say I have a Hotels and Rooms. I have 3 use-cases that come up:
- Retrieve a hotel with all of its rooms
- Retrieve a hotel (without rooms)
- Retrieve a room
Now the last 2 seem simple enough to me, I would have some kind of findHotelById
and findRoomById
methods in my repositories. Now what is the best practice for retrieving both the hotel and the rooms? Should I have a findHotelByIdWithRooms
method? Should I call findHotelById
and then call findRoomsByHotel
and populate the rooms on my model (ex: hotel.setRooms(rooms)
) after the fact? Or should findHotelById
take in some parameter to optionally include rooms in the result?