Can \yii\db\Query() return array of objects ?

I have this test method, where I am using \yii\db\Query().


public static function test()

{

    return (new \yii\db\Query())

    ->select('post_id')

    ->from('comment')

    ->where(['in', 'id', [9, 94]])

    ->all();

}  

To display results I have to do this:




<?php foreach (Model::test() as $test): ?>

    <?= $test['post_id'] . "<br>" ?>

<?php endforeach ?>

But I would like to have array of objects to work with like this:


<?php foreach (Model::test() as $test): ?>

    <?= $test->post_id . "<br>" ?>

<?php endforeach ?>

Is this possible somehow ? Also Is it possible with DAO too ?

I ma using \yii\db\Query() and DAO because I will have to write some really complex sql queries and do not know how to do them with AR. Thanks

Anyone ?

http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#querying-data-from-database

At the bottom of "Querying Data from a Database":




// to retrieve customers using a raw SQL statement:

$sql = 'SELECT * FROM customer';

$customers = Customer::findBySql($sql)->all();