mardi 31 mars 2020

Junction table with DAO design pattern

I have a question regarding the DAO design pattern.

I have 3 tables called user, role and user_role. In my application I have two DAOs, UserDao and RoleDao. I also have two services that use the DAOs, UserService and RoleService.

How can I do if when I get all the users I also want to get the roles associated to each user? Should I have my user domain model populated with all the information in the UserDao performing all the neccessary queries to all related tables? Or should I have the UserService service call both Dao's to get the user first and then their roles to fill user domain model (entity)? Which way of doing it is the most correct in relation to good practices? Is a new DAO related with the junction table needed?

Thank you very much!

Aucun commentaire:

Enregistrer un commentaire