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

Overwriting Model::find() with the data modification

Hi, I need to create a custom find() function and overwrite the data based on application logic.

   public static function find($parameters=null)
    {
        $records = parent::find($parameters);

        foreach ($records as $record) {
            if ($record->parent_id) {
                $record->name = '...';
            }
        }
        return $records;
    }

This code will not work! Pasted as an explanation.

For this pupose you can use afterFetch event instead of overriding find() method. Please read https://forum.phalcon.io/discussion/523/how-to-elegantly-transform-field-in-model-