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

How to set a different table name for a specific model?

Hi There,

Case 1: I have been looking for a way on how to set the model with a different table name. I found setSource() under Model but I don't see any example to use it. I tried ways to use it like calling it from a constructor but it does not allow me to use a constructor on a model that inherits the Model class.

How am I suppose to use this or what is the appropriate to do this? I am using micro framework by the way in case the implementation seems to be different and all.

Case 2: How do we deal with multi databases too? I noticed in the example that we need to set different connections for each but I find this inefficient in my case. I have several databases but these databases interact and I have queries that gets data from tables residing from different databases. How do we implement this one in Phalcon? Much preffered though using only the current connection instead of creating different instances and just play around it via query.

Thanks a lot, icewing02


Case 1:

class YourModelname extends \Phalcon\Mvc\Model
    public function getSource()
        return "your_database_name";

Case 2: Take a look on Relationships between Models


Thanks Arthur for the prompt reply! Sorry it took me a while to get back. I will be testing it today and see if things works perfectly here, and go back here for updates.


Sorry for the late reply. Cheers! Things are working well. Two thumbs up!