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 table mapping

I might have missed this in the documentation (forgive me if i did) but i cannot seem to figure out how to map a model to a different table. E.g. let's say i have a model 'Car' and i would like to map it to a table named 'cars', how would i be able to achieve this?



900
Accepted
answer
edited May '14

You can simply set the database source of your model:

class Car extends \Phalcon\Mvc\Model
{
    public function getSource()
    {
        return 'cars';
    }
}

Alternative:

class Car extends \Phalcon\Mvc\Model
{
    public function ìnitialize()
    {
        $this->setSource('cars');
    }
}