We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Catchable fatal error: Object of class Phalcon\Mvc\Model\Resultset\Simple could not be converted to string

Hello i have a problem to display Model result in Volt:

Controller:

$totalLikes = $this->modelsManager->createBuilder()
        ->columns(["totalLikesDB"=>"SUM(l.likeClicks)"])
        ->from(["u" => "Vokuro\Models\Users", "l" => "Vokuro\Models\Likes"])
        ->where("u.id = l.usersId")
        ->groupBy("u.id")
        ->getQuery()
        ->execute();

    $this->view->setVar("totalLikes", $totalLikes);

Generated SQL:

SELECT SUM(`l`.`likeClicks`) AS `totalLikesDB` FROM `users` AS `u`, `likes` AS `l` WHERE `u`.`id` = `l`.`usersId` GROUP BY `u`.`id`

Volt:

{{ totalLikes.totalLikesDB }}

Error:

Catchable fatal error: Object of class Phalcon\Mvc\Model\Resultset\Simple could not be converted to string 


59.9k
Accepted
answer

I found a solution:

           {% for sumLikes in totalLikes %}
                {% if user.id ==  sumLikes.id %}
                    {{ sumLikes.totalLikesDB }}
                {% endif %}
            {% endfor %}