Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



609
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');
    }
}