G
G
galithr2016-10-11 14:08:00
Yii
galithr, 2016-10-11 14:08:00

Selecting model fields, where is it better to do it?

When selecting data in Yii2, it is possible to specify which fields to select, for example:

Model::find()->select(['id', 'name', 'date_created']);

But the question is where is it more correct and more logical to form a list of these fields? In the controller? so the controller should not know such information about the model. Or add what method to model/ActiveQuery ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Максим Тимофеев, 2016-10-11
@galithr

Если задаться идеей "не навреди мозгу теоретика" то конечно в ActiveQuery
Но исходя из структуры yii2 часто удобнее в контроллере. Смысл раздувать ActiveQuery если такой набор используется 1 раз. Если есть необходимость использовать повторно, то точно есть смысл вынести в ActiveQuery.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question