If you need the information, and it can be done with one query, You need to do it with one query. Unless the business logic doesn't require that.
Jul 3, 2022
1
Level 3
General best practive question: Javascript or query?
I'm currently using a prop that is a query on a model 'student' that returns all students currently enrolled. A property of student is homeroom and I also need an array of each distinct homeroom of currently enrolled students.
Is it better to perform another query on the student model to make an additional 'homeroom' prop? Or is it better to use javascript to make it from the student prop already queried? Same would go for aggregates...
I get that each circumstance is unique, but generally speaking, is it poor practice to query the same table more than once in a request?
Please or to participate in this conversation.