Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 


21.5k
Accepted
answer

I found a solution:

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