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.

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?



61.1k
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.phalconphp.com/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!



11.3k

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



11.3k

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



61.1k

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