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

Model clear related models

Hi all,

I have a situation where I load a model $Interaction that is related to models Departments. I then do a bunch of separate operations that affect which departments are related to $Interaction. After these operations, I call $Interaction->refresh(). However I find that $Interaction->Departments still gives me the models that were related before the operations are done. To get $Interaction->Departments to update, I have to re-query for a new $Interaction.

Is there a way to "purge the cache" so to speak? I know related models are loaded lazily - is there a way to tell model that it needs to reload related models?


Do you ask about option reusable?

class Robots extends \Phalcon\Mvc\Model
    public function initialize()
                "reusable" => true,    // cache the results of this relationship
                "alias"    => "parts", // Alias of the relationship

Thanks for the reply. I don't want to affect the relationship, because for most parts of the application the existing behaviour is fine. What I need to do is find a way to clear the cache on-demand.