Answer the question
In order to leave comments, you need to log in
How to correctly organize the output of a field if it is in another table?
Hello.
There is a table of reviews, it contains, in addition to thematic fields (comment, rating), the user_id field. But on the front-end, the output of user_id will be inconvenient for users, but I would like to display the username.
But to get the username, each review needs +1 request to get user information by id. Thus, for 5 reviews + 5 requests. I don't think this is the best option. There is an idea - to store a copy of the username in the feedback table, but is this correct?
What is the correct option in this situation - requests, or storing a copy of the username? Or are there any other correct options?
Thanks for answers.
Answer the question
In order to leave comments, you need to log in
What you are looking for is called relational data:
www.yiiframework.com/doc-2.0/guide-db-active-recor...
as Anton said , first set up the relation. After that, just implement eager loading and regardless of the number of records, you will always have 1-2 queries
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question