Answer the question
In order to leave comments, you need to log in
Is it possible to make a select from a controller in a custom method that inherits from ActiveController, taking into account fields?
Well, that is, do not write , but simply . In this case, it will only be selected , because in the User model, it is written:User::find()->select('username')->all()
User::find()->all()
username
public function fileds()
{
return ['username'],
}
Answer the question
In order to leave comments, you need to log in
As a result, at random, I found out that when you add a method ->asArray()
to the request chain, then the method fields()
in the model starts to be ignored. If you did not register it, then the method ->select(column1, column2)
becomes analogous to the fileds line in the url, for example:
somedomain.ru/v1/back?fields=id,name
. That is, if the method is not registered, then all fields from fileds are returned, but if 2 out of 3 fields of fileds are registered and specified, for example, then each record will receive its first 2 fields and 3 will always be null
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question