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

Even when a record is queried?

I see many events (beforeUpdate, beforeSave etc) but I want to convert a value to real boolean right after its "find" or "findFirst"-ed. How can I do it?



85.5k
Accepted
answer

Class Model {

    public $bool;

    function afterFetch(){
        if php >= 5.5.
            $this->bool = boolval($this->bool);
        else 
            $this->bool = (bool) $this->bool
    }

If i understand you right, a user had same issue few days ago. Check this topic and the accepted answer: https://forum.phalcon.io/discussion/9095/model-describe

Tell us if that helped you.

@kisb2 Izo's solution is cleaner then mine;

@izopi4a thanks for sharing, i kinda missed that from the docs, really usefull!



28.2k

yea, right. Actually I was browsing at https://docs.phalcon.io/en/latest/reference/models.html#events-and-events-manager but "afterFetch" is not in that "Events and Events Manager" table



28.2k

UPDATE: but it wont effect the resultset if I convert it to array (->toArray();)



85.5k

show me you db connection, the whole piece of the pie :D . Without the password ofcourse