Yii2 response type casting issue.

I am facing a weird issue in Yii2, in simple select query when I use asArray()->all() it returns everything as string, when I tried only all() it does not convert everything into string but issue is it only returns single table data I have join in query it skips other tables fields it also skip relational data.

I also tried one()->toArray() but result same it skips other tables fields only bring single table data. Did anyone else face this same issue any help would be highly appreciated.



See the note.

I already mentioned my above question that I am using asArray() which return everything in string I need proper data type casting.

In the first place, why do you have to use "asArray()" instead of ActiveRecord object?

asArray() may be fast and requires less memory. But it lacks the convenience of ActiveRecord.

asArray() will return everything in string. It’s by design.

/* Have you read the part of the guide I mentioned? */

Look at this for detail issue. http://stackoverflow.com/questions/38724778/yii2-response-type-casting-issue

I also used active record object but as I mentioned it skips fields of joined tables and relations, please go through above question on stackoverflow all queries and their response are printed there. Thanks

Things seem to be a bit upside-down in your understanding of "asArray()".

Yii uses PDO to handle the db operations at its base layer, in which the query results are stored in arrays of strings. And ActiveRecord objects will be created using those arrays, converting the strings to proper data types. "asArray()" just instructs Yii to return the arrays without converting them to objects.

As for your JSON encoded result of the ActiveRecord version in which the related models are missing, I think it’s probably because of the way you convert ActiveRecord object(s) to JSON.

And, well, you didn’t answer my question yet. Why do you have to use “asArray()” in the first place?