How to add model virtual attributes to asArray result

Hi Every one.

I’m using some models methods to return some formated data like getFullName() to return first_name concatenated with last_name but the issue i want asArray which giving better performance but don’t know how to return virtual attribute like full_name to the asArray result, can any one help.

Regards,

ActiveQuery::asArray() can be faster because it doesn’t populate model instances from the result. Without model instances you can’t access model features like virtual attributes. There’s no way to simply get the best from both worlds without all the disadvantages.

If populating model instances is proven to be a real performance bottleneck in your application, try to execute a plain sql query instead and concatenate columns in the SELECT part of it.