How I can return an object instead of an array

Good day.

I am trying to return a M object instead of a M array.

See controller below: -

$query = $this->P->find();

See model below: -

public function findTotalPaid(Query $query)
	$query= $this->find()
			->select(['M.Id','amount_paid' => $query->func()->sum('amount')])
			->where(function ($exp){
				return $exp
	return $query;

See view below: -

            <td><?= h($amount->m['Id']) ?></td>
            <td><?= h($amount->amount_paid) ?></td>
			<!--<td><= h($amount['amount_paid']) ?></td>-->
        <?php endforeach; ?>

The problem is that I get an array with the m id in it instead of a m object.

Someone please tell me how I can get a m object instead of an m array.

findTotalPaid returns a query object. So somewhere else you call toArray() if you get an array at the view.