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

afterFetch + createBuilder

Hi, i have a situation that need a createBuilder and in resultset i need that should execute method afterFetch of model class, this method will convert the format of date. how i can resolve this problem with createBuilder, what is better way?



125.8k
Accepted
answer

Have you tried this? Without testing, my guess would be that afterFetch() gets called on the models after the query is executed. Remember the query isn't necessarily executed when the builder is created, but when it's data is first access.

Another solution might be to declare the date as a private class variable. Then, override __get() and __set() to convert the format at the time the variable is retrieved and set.

It should be called until you select full objects.