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.
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?