For example, there is the User entity (we will omit the getters and setters):

class User { private $id; private $email; private $phone; private $status; private $name; private $surname; private $avatar; private $visit_at; 

Sometimes entities are very large, and in specific cases, let's say quite a bit of data is not needed. For example, a User entity may have many properties, including a profile, access permissions, and so on. However, essentially only a full name or only a part of the data may be required.

From here it makes no sense to make a heavy request and fill the whole entity only to display the user name. Therefore, I can make a request of the form:

 SELECT id,name,surname FROM users .... 

Therefore, the question arises: is it correct to fill in an entity not entirely, but only with necessary data, or do you need to create such mini entities for all occasions?

  • Smacks here inheritance. Human -> Account - Anton Shchyrov
  • probably, any normal ORM framework when retrieving data allows you to specify which connected entities to extract, and which fields to extract at all. so this approach is quite normal. But to produce a million classes just does not make any sense, especially tied as the same table. - teran

0